ios - TableView 标签上显示的 TableView 数据

标签 ios json

我是 iOS 开发新手,我想知道当我单击表格行时,表格 View 中显示的数据应该在标签上选择。我的标签名为 City。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableItem";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    cell.textLabel.text = [arrayname objectAtIndex:indexPath.row];

    return cell;
}

最佳答案

在 viewDidLoad 中添加这个数组

dataArr=[[NSMutableArray alloc]initWithObjects:@"Hyderabad",@"Bangalore",@"Chennai",@"Pune",@"Mumbai", nil];


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{
    NSString *reUseid=@"cellID";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:reUseid];

    if (cell==nil)

    {

        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reUseid];

    }

    cell.textLabel.text = dataArr[indexPath.row];
    return cell;
}

这里是 TableView didSelectRowAtIndexPath 方法。

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

{

     NSLog(@"selected is %@",[dataArr objectAtIndex:indexPath.row]);

    [self performSegueWithIdentifier:@"viewToDescriptionSegue" sender:self];

}

在这个方法中你得到了indexpath,你可以从中得到选定的行,比如indexpath.row,你可以从中得到数组中的对象。

关于ios - TableView 标签上显示的 TableView 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32990747/

相关文章:

ios - 在 AIR 应用程序中集成像 ShareKit 这样的库?

ios - Swift 3 - 调整字体大小以适合宽度,多行

java - 我应该如何读取带有编号对象的 JSON?

mysql - 将学说数组转换为 JSON

java - Jackson @JsonIgnoreProperties - 组合规则

ios - 具有 204 响应且 Objective-C 中没有内容的 DELETE 请求的巨大延迟

ios - 识别 View 中而非 subview 中的滑动手势

ios - 从 UIButton 单击自定义 XIB 触发操作

javascript - 处理 JSON 对象数组

JSON 对象解析但省略了集合中的第一项