好的,所以我想将一个视图控制器中表格单元格中包含的名称传递给另一个视图控制器中的数组。我想通过一个也包含在第一个表的单元格中的按钮来执行此操作。
以下是描述表格单元格的地方:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// add "add" button
UIButton *addFriendButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
addFriendButton.frame = CGRectMake(250.0f, 5.0f, 75.0f, 30.0f);
[cell addSubview:addFriendButton];
[addFriendButton addTarget:self
action:@selector(addFriend:)
forControlEvents:UIControlEventTouchUpInside];
if(!cell)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [array objectAtIndex:indexPath.row];
return cell;
}
这里是描述按钮方法的地方:
- (IBAction)addFriend:(id)sender
{
NSLog(@"Add friend.");
}
第一个视图控制器的名称 - 执行传递的控制器 - 称为 ViewController - 而第二个视图控制器 - 接收传递信息的控制器 - 称为 MyMealViewController。我希望将传递的信息存储在其中的数组称为 myMenuArray。
我认为这基本上是所有相关信息。如果您需要我提供任何其他信息 - 或者如果您需要澄清我提出的问题 - 为了使我的问题可以回答,请告诉我!