将字符串传递给表单元格视图

时间:2011-09-16 20:15:04

标签: iphone

将字符串传递给另一个视图,但没有成功。

我有一个带按钮的选择器:

picker.m

    @synthesize marray2, marray1;

    -(IBAction)show:(id)sender

    {

NSInteger breadRow = [mpicker selectedRowInComponent:kBreadComponent];

NSInteger fillingRow = [mpicker selectedRowInComponent:kFillingComponent];

NSString *bread = [self.marray2 objectAtIndex: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];

    }

我想将'message'传递给另一个使用表格单元格绘制的视图:

(摘自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;

}

现在让我的任务变得困难的是我有一个标签栏控制器,它是app委托中的子视图,我已经在导航控制器中包裹了表视图,当点击一个单元格时,它带来了选择器视图一旦按下按钮,就应该恢复到表视图,并且单元格中填充了食物选择。

任何人都可以帮助而不必回复单身人士或涉及应用代表吗?

谢谢,我高兴地等待你聪明的解决方法:)

崔佛

1 个答案:

答案 0 :(得分:0)

发布NSNotification并在object参数中传递消息。