I have an issue with an imported array and UITableView. I have imported the view mondayView and am trying to access monArray from that view. Here is my code. The bold gets the following error:
Expected ':' before '.' token.
Code:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return [mondayView.monArray count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return 10;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
cell.textLabel.text = [mondayView.monArray objectAtIndex:indexPath.row];
return cell;
}
I have an issue with an imported array and UITableView. I have imported the view mondayView and am trying to access monArray from that view. Here is my code. The bold gets the following error:
Expected ':' before '.' token.
Code:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return [mondayView.monArray count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return 10;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
cell.textLabel.text = [mondayView.monArray objectAtIndex:indexPath.row];
return cell;
}
the syntax you are using, "mondayView.monArray", assumes that your MondayView object has a property monArray. The error you say you're getting suggests that you have an instance variable monArray, but forgot to declare it as a property of your mondayView object.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Ok while trying to get out the easy way, I have been able to work out how to use a singleton object! Finally found somewhere which explained it so I could understand. Anyway I have it working globally now. Thanks.