0

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

在主视图中:

-(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 只包含一个标签。

我第一次单击它会显示“标签”,但它在以下尝试中有效。

我想我需要初始化一些我错过的东西,但我找不到它。

先感谢您

4

3 回答 3

2

我无法理解您为什么要使 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];
}

这可能会帮助你...

于 2012-06-28T11:30:13.070 回答
0

采用 -

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

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

[[self navigationController] pushViewController:self.read animated:YES];
于 2012-06-28T11:07:57.130 回答
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在as中创建一个实例变量

     @property(assign) int index;

     @synthesize index;

readNoticeviewDidLoad 方法中,您只需调用updateRowNumber

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

它将按您的预期显示数字

于 2012-06-28T11:33:35.437 回答