0

アプリで今後のイベント テーブルを作成しようとしていますが、行を選択すると indexPathForSelectedRow は常に 0 を返します。

NSArray *upcommingTitle;
NSMutableArray *upcommingSubtitle;
NSMutableArray *upcommingTime;

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)datesTable numberOfRowsInSection:(NSInteger)section
{
    return upcommingTitle.count;
}


-(UITableViewCell *)tableView:(UITableView *)datesTable cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"Cell";

    DatesCustomCell *Cell = [datesTable dequeueReusableCellWithIdentifier:cellIdentifier];

    if(!Cell)
    {
        Cell = [[DatesCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }

    Cell.DatesTitle.text = [upcommingTitle objectAtIndex:indexPath.row];
    Cell.DatesSubtitle.text = [upcommingSubtitle objectAtIndex:indexPath.row];
    Cell.DatesTime.text = [upcommingTime objectAtIndex:indexPath.row];

    return Cell;
}

self.datesTable.dataSource = self;
self.datesTable.delegate = self;

読み込み済みの表示

upcommingTitle = [[NSMutableArray alloc] initWithObjects:@"Title1", @"Title2", nil];
upcommingSubtitle = [[NSMutableArray alloc] initWithObjects:@"Sub1", @"Sub2", nil];
upcommingTime = [[NSMutableArray alloc] initWithObjects:@"Date1", @"Date2", nil];

ただし、次の例では常に 0 が返され、"test" ラベルが "Title1" になります。

ビューは表示されました

_test.text = [upcommingTitle objectAtIndex:self.datesTable.indexPathForSelectedRow.row];

助けてくれてありがとう

4

4 に答える 4

1

didSelect メソッドで別のビューをプッシュしてみてください

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Here, indexpath returns the selection of cell's indexpath, so put your code here

_test.text = [upcommingTitle objectAtIndex:indexPath.row];

//then push your view 

}

UPDATED : 次に、このコードを使用します

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([[segue identifier]isEqualToString:@"pushView"])
    {
        NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
        PushingViewController *pushView = [segue destinationViewController];
        pushView._test.text = [upcommingTitle objectAtIndex:indexPath.row];

    }
}
于 2013-10-01T11:11:44.057 に答える
0
(void)tableView:(UITableView *)datesTable didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
_test.text = [upcommingTitle objectAtIndex:indexPath.row]; 
}

Just put this code in your application.
于 2013-10-01T11:12:47.950 に答える