ios - 如何在 iphone 中获取单元值?

标签 ios objective-c uitableview

在我的 iphone 应用程序中,uiTable 中有 4 个单元格,每个单元格都有整数值(10、12、13、14)。如何在我单击每个单元格时检索整数值? 以及如何放置 if 条件来检查单元格的值是否相同? 即

if(cell value==condition){

}

最佳答案

UITableViewControllerdidSelectRowAtIndexPath 方法中,只需提取标签文本值。

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

    NSString *s = [[[tableView cellForRowAtIndexPath:indexPath] textLabel] text];
    NSLog(@"String is: %@", s);

    int i = [s intValue];
    NSLog(@"This is the int value: %d", i);

    // Compare string or int to other value...
}

关于ios - 如何在 iphone 中获取单元值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1570756/

相关文章:

ios - 简单自定义 UITableViewCell 的自动布局错误

ios - completionHandler - 表达式类型不明确,没有更多上下文

ios - 单个 UILabel 中的粗体和非粗体文本?

objective-c - 返回方法 Objective-C 中的 dispatch_async

ios - 在 UIView 中初始化 UIScrollView 显示警告 : 'Local declaration hids instance variable'

iPhone: "Locking"TableView 顶部的单元格

ios - 删除 UITableViewCell 之间的灰线

iphone - 使用 Nib 的带有 TableView 的 UITabBar

ios - 已达到 Apple 开发者 iOS 设备注册上限

ios - 如何在 SpriteKit 中为 physicsWorld 设置 contactDelegate?