导航视图无法首次单击

时间:2012-06-28 11:06:08

标签: iphone objective-c xcode4

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

在mainView中:

-(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仅对Label进行内容。

我第一次点击它显示“标签”,但它可以进行以下尝试。

我想我需要尝试一些我错过的东西,但我找不到它。

提前谢谢

3 个答案:

答案 0 :(得分:2)

我无法理解为什么你做了变量....?用这个..

-(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];
}

这可能会对你有帮助......

答案 1 :(得分:0)

使用 -

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

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

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

答案 2 :(得分:0)

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

 -(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方法中,您只需拨打updateRowNumber

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

它会按预期显示数字