Iphone 导航视图没有';第一次点击就不能工作

Iphone 导航视图没有';第一次点击就不能工作,iphone,objective-c,xcode4,Iphone,Objective C,Xcode4,我有一个导航视图,当我单击时,我只显示行号 在主视图中: -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if (read == nil) { readNotice *aController = [[readNotice alloc]initWithNibName:@"readNotice" bundle:nil]; self.read =

我有一个导航视图,当我单击时,我只显示行号

在主视图中:

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

if (read == nil) {
    readNotice *aController = [[readNotice alloc]initWithNibName:@"readNotice" bundle:nil];
    self.read = aController;   
}

[read updateRowNumber:indexPath.row];

[[self navigationController] pushViewController:read animated:YES];
在我的
readNotice
课程中:

-(void)updateRowNumber:(int)theindex {

rowNumber = theindex + 1;

message.text = [NSString stringWithFormat:@"row %i was clicked", rowNumber];

NSLog(@"view did load row = %d", rowNumber);

}
readNotice.xib仅包含一个标签

我第一次点击它时会显示“标签”,但在下面的尝试中它会起作用

我想我需要对我错过的东西进行初始化,但我找不到它

提前感谢

使用-

if (self.read == nil) {
    readNotice *aController = [[readNotice alloc]initWithNibName:@"readNotice" bundle:nil];
    self.read = aController;   

}
--------
---------

[[self navigationController] pushViewController:self.read animated:YES];

我不明白你为什么把read变量?用这个

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

  readNotice *aController = [[readNotice alloc]initWithNibName:@"readNotice" bundle:nil];
  [self.navigationController pushViewController:aController  animated:YES];
  [aController updateRowNumber:indexPath.row];
}
希望这能帮助你

试试这个, 在tableview:DidSelectRowatinex方法中

 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

 if (read == nil) {
    readNotice *aController = [[readNotice alloc]initWithNibName:@"readNotice" bundle:nil];
    self.read = aController;   
 }

 read.index = indexPath.row;
 [[self navigationController] pushViewController:read animated:YES];
readNotice
中创建一个实例变量,如下所示

     @property(assign) int index;

     @synthesize index;
readNotice
viewDidLoad方法中,只需调用
updateRownNumber

 - (void)viewDidLoad 
 {
   [super viewDidLoad];
   [self updateRowNumber:index];
 }

它将按照您的预期显示数字

我只建议使用适当的视图控制器,所需的rest代码需要到位。当您单击单元格时,新的视图控制器是否打开?