Pla*_*sma 15 uitableview ios6 ios7
我希望现在苹果公司能够接受IOS 7的应用,我们可以谈谈它吗?
我正在尝试修复我的应用程序,因此它适用于IOS 7并且今晚取得了一些非常好的进展.我有两个悬而未决的问题,但会分别发布.第一个问题是这一行(我在调试后添加了一个日志行)...
NSIndexPath *indexPath = [settingsTableView indexPathForCell:(UITableViewCell *)[sender superview]];
NSLog(@"Changed %@ <-**-> %@", [sender superview], indexPath );
Run Code Online (Sandbox Code Playgroud)
日志显示....
IOS 7
2013-09-11 22:18:02.985 BusTimes[21013:a0b] Changed <UITableViewCellScrollView: 0xbfc1c80; frame = (0 0; 320 44); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0xbfc1e70>; layer = <CALayer: 0xbfc1540>; contentOffset: {0, 0}> <-**-> (null)
2013-09-11 22:18:08.577 BusTimes[21013:a0b] Changed <UITableViewCellScrollView: 0xbfc62d0; frame = (0 0; 320 44); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0xbfc64c0>; layer = <CALayer: 0xbfc5b90>; contentOffset: {0, 0}> <-**-> (null)
Run Code Online (Sandbox Code Playgroud)
IOS 6
2013-09-11 22:25:34.495 BusTimes[2116:907] Changed <UITableViewCell: 0x20862f40; frame = (0 179; 320 44); text = 'Reminder Mins: 5'; autoresize = W; layer = <CALayer: 0x208523d0>> <-**-> <NSIndexPath 0x20861430> 2 indexes [0, 3]
2013-09-11 22:25:47.499 BusTimes[2116:907] Changed <UITableViewCell: 0x20865180; frame = (0 223; 320 44); text = 'AutoRefresh Secs: 60'; autoresize = W; layer = <CALayer: 0x20865340>> <-**-> <NSIndexPath 0x2085c0d0> 2 indexes [0, 4]
Run Code Online (Sandbox Code Playgroud)
所以在IOS 7上,indexPath始终为(null),而.section和.row总是为0.但这在IOS 6上工作正常,并返回.section 0和第3行,以及.row 4.任何人都可以建议我如何获得IOS 7对我来说以同样的方式行事?
提前谢谢了.
等离子体
*解决方案 - 我在评论后将代码更改为此
UIView *view = sender;
while (![view isKindOfClass:[UITableViewCell class]]) {
view = [view superview];
}
NSIndexPath *indexPath = [settingsTableView indexPathForCell:(UITableViewCell *)view];
Run Code Online (Sandbox Code Playgroud)
对单元格的视图层次结构不做任何假设通常会更安全。过去,我在 UIView 上使用了带有类似方法的类别来查找作为单元格的超级视图:
- (UIView*)ancestorOrSelfWithClass:(Class)cls {
if ([self isKindOfClass:cls]) {
return self;
} else if (self.superview) {
return [self.superview ancestorOrSelfWithClass:cls];
} else {
return nil;
}
}
Run Code Online (Sandbox Code Playgroud)
因此,您将要求[sender ancestorOrSelfWithClass:[UITableViewCell class]]获取实际的单元格,并且无论单元格中存在什么层次结构,它都会起作用。
| 归档时间: |
|
| 查看次数: |
4154 次 |
| 最近记录: |