pass string to table cell view
im tring to pass a string to another view but with no success.
I have a picker with a button:
picker.m
@synthesize marray2, marray1;
-(IBAction)show:(id)sender
{
NSInteger breadRow = [mpicker selectedRowInComponent:kBreadComponent];
NSInteger fillingRow = [mpicker selectedRowInComponent:kFillingComponent];
NSString *bread = [self.marray2 objectAtInd开发者_StackOverflowex:breadRow];
NSString *filling = [self.marray1 objectAtIndex:fillingRow];
NSString *message = [[NSString alloc] initWithFormat:@"Your %@ and %@ will be right up.", filling, bread];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@" Thank you " message:message delegate:nil cancelButtonTitle:@" OK " otherButtonTitles:nil];
[alert show];
[alert release];
[message release];
}
i want to pass 'message' to another view which uses table cell drawing:
(excerpt from FoodOutput.m):
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyIdentifier";
MyIdentifier = @"tblCellView";
TableCellView *cell = (TableCellView *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if(cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"TableCellView" owner:self options:nil];
cell = tblCell;
}
/*if(message== nil){ food = [[NSMutableArray alloc] initWithObjects:@"choose your food", nil];} else {food = [[NSMutableArray alloc] initWithObjects:[self message],nil];}*/
arrayNum = [[NSArray alloc] initWithObjects:[NSString stringWithFormat:@"%d", indexPath.row+1],nil];
//This is where i want to use message from the other view:
[cell setLabelText:message];
//But that doesn't work???????
[cell setLabelRowNum :[arrayNum objectAtIndex:0]];
return cell;
}
now what makes my task difficult is that I've got a tab bar controller which is the subview in the app delegate, and I've wrapped up the table view in a nav controller, which when clicking on a cell, brings up the picker view, which in turn once the button is pressed, is supposed to revert back to the table view with the cell populated with the food choice.
Can anybody help without having to revert to singletons or involving the app delegate?
Thanks and i await your clever workaround with glee :)
Trev
Post an NSNotification and pass the message in the object parameter.
精彩评论