美好的一天! 這裏有一個問題:我在我的UITableView增加細胞的按鈕編程這樣的:如何在單元子視圖中找到按鈕
UIButton *button = [[UIButton alloc] initWithFrame:buttonFrame];
[button setImage:[UIImage imageNamed:@"Button_off_weather"] forState:UIControlStateNormal];
button.tag = indexPath.row;
[button addTarget:self action:@selector(buttonCityTapped:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview: button];
它工作正常。 然後我想找到它的表格和關閉這樣的:
NSMutableArray *cells = [[NSMutableArray alloc] init];
for (NSInteger j = 0; j < [_tableView numberOfSections]; ++j)
{
for (NSInteger i = 0; i < [_tableView numberOfRowsInSection:j]; ++i)
{
[cells addObject:[_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:j]]];
for (UITableViewCell *cell in cells)
{
for (id theView in cell.subviews) {
if ([theView isKindOfClass:[UIButton class]]) {
[theView performSelector:@selector(buttonOff:)];
}
}
}
}
}
這不起作用。有什麼想法嗎?
請清楚地分享你的問題。 – sathiamoorthy