2014-04-28 62 views
0

我知道我們可以在導航樣式中通過「單元格」推送一些數據到下一個UIViewController。但是,我們是否也可以這樣做:原型單元格「模態」將數據傳遞給下一個UIViewController? 這裏是我的tableview實現的一部分。UITableViewController單元模態傳遞數據到下一個UIViewController

- (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個NSString的到目的地的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的要顯示的標題爲「姓名+姓」

@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

你的錯誤告訴你,類ChatViewController沒有一個名爲passedOverEmailID的屬性,但在你的代碼中,你正試圖在MessagesViewController類上設置passedOverEmailID。你確定segue.destinationViewController在storyboard中設置爲MessagesViewController嗎?你的錯誤會表明它不是。另外,我總是喜歡在引用segue.destinationViewController時強制類類型,所以我建議使用MessagesViewController * messageVc =(MessagesViewController *)[segue destinationViewController]; –

+0

你,你說得對.... ....傻 – seph

回答

0
MessagesViewController *messageVc = (MessagesViewController *)[segue destinationViewController]; 

這是不正確的,在destinationVC應該是不同的!

相關問題