我知道我们可以做" cell"推送导航样式将一些数据传递给下一个UIViewController。 但是,我们也可以这样做,原型单元"模态"将数据传递给下一个UIViewController? 这是我的tableview实现的一部分。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.chatPeople count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = @"chatCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
NSString *fn = [[self.chatPeople objectAtIndex:indexPath.row] objectForKey:@"first_name"];
NSString *ln = [[self.chatPeople objectAtIndex:indexPath.row] objectForKey:@"last_name"];
cell.textLabel.text =[NSString stringWithFormat:@"%@ %@", fn, ln];
cell.textLabel.textAlignment = UITextAlignmentRight;
return cell;
}
现在我正在尝试将3个NSStrings传递到目标ViewController
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSString *toChatEmailID = [[self.chatPeople objectAtIndex:indexPath.row] objectForKey:@"id"];
NSString *fn = [[self.chatPeople objectAtIndex:indexPath.row] objectForKey:@"first_name"];
NSString *ln = [[self.chatPeople objectAtIndex:indexPath.row] objectForKey:@"last_name"];
MessagesViewController *messageVc = [segue destinationViewController];
messageVc.firstName = fn;
messageVc.lastName = ln;
messageVc.passedOverEmailID = @"1";
}
现在在我的目的地VC中,我希望这个VC的标题显示为" firstname + lastname"
@interface MessagesViewController ()
@end
@implementation MessagesViewController
@synthesize menuBtn;
@synthesize chatBtn;
@synthesize passedOverEmailID;
@synthesize firstName;
@synthesize lastName;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"%@ %@", firstName,lastName);
self.navigationItem.title = [NSString stringWithFormat:@"Chatting with %@ %@", firstName, lastName];
}
以下是错误:
[ChatViewController setPassedOverEmailID:]: unrecognized selector sent to instance 0x8b4e0c0
2014-04-28 21:36:41.033 WeNetwork[1895:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ChatViewController setPassedOverEmailID:]: unrecognized selector sent to instance 0x8b4e0c0'
任何人都可以给我一些帮助,欢呼声
答案 0 :(得分:0)
MessagesViewController *messageVc = (MessagesViewController *)[segue destinationViewController];
这不正确,destinationVC应该是另一个!