我得到的UITableViewCell一個UIButton屬於這樣的:獲取的UITableViewCell與上海華在iOS的7
-(void)buttonHandler:(UIButton *)button {
OrderCell *cell = [[button superview] superview];
NSLog(@"cell.item = %@", cell.item.text);
而且它在任何iOS的7前工作正常,但給我:
[UITableViewCellScrollView項目]:如果我在的iOS 7上運行應用程序,但如果我這樣做發送到實例0x17ae2cf0
無法識別的選擇:
-(void)buttonHandler:(UIButton *)button {
OrderCell *cell = [[[button superview] superview] superview];
NSLog(@"cell.item = %@", cell.item.text);
然後它在iOS 7中工作,但不是更早?!?!?!
我做這個繞過這個問題:
OrderCell *cell;
if([[[UIDevice currentDevice] systemVersion] isEqualToString:@"7.0"])
cell = [[[button superview] superview] superview];
else
cell = [[button superview] superview];
NSLog(@"cell.item = %@", cell.item.text);
但跆拳道是怎麼回事!? 有誰知道爲什麼會發生這種情況?
謝謝!
你的代碼是根據的UITableViewCell的'私有子視圖結構'。很明顯,iOS 7中的結構已經發生了變化。有很多更安全的方法來執行您想要的操作。並且你的新代碼將在iOS 7.1和iOS 8下破解。 – rmaddy
@rmaddy什麼是更安全的方式? – Mundi
你可以遍歷superviews,檢查它們是否是類類型的UITableViewCell,然後返回該視圖?看到回答: – CW0007007