具有索引0 I有一個UITableView
我UIViewController
內部。數據,字幕數據和附件按鈕均可正常加載;但是,當我按下任何附件按鈕,他們都返回索引0? dataSource
和delegate
連接到文件的所有者在.xib我缺少什麼?表視圖細胞似乎當按鈕被竊聽
頭文件
@interface OrderPage : UIViewController <UITableViewDataSource, UITableViewDelegate> {
NSDictionary *userOrderData;
NSMutableArray *myMasterList;
UITableView *tableView;
NSMutableArray *contentss;
NSMutableArray *mysendArray;
NSDictionary *my_data;
}
-(IBAction)sendOrders;
@property(nonatomic, retain) NSDictionary *userOrderData;
@property (nonatomic, retain) IBOutlet UILabel *firstOrder;
@property(nonatomic, retain) NSMutableArray *myMasterList;
@property(nonatomic, retain) UITableView *tableView;
@property(nonatomic, retain) NSMutableArray *contentss;
@property(nonatomic, retain) NSMutableArray *mysendArray;
@property(nonatomic, retain) NSDictionary *my_data;
@end
實現,我cellForRowAtIndexPath:
(按鍵部分):
@synthesize tableView = _tableView;
UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
button.tag = indexPath.row;
[button addTarget:self action:@selector(checkButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor = [UIColor clearColor];
cell.accessoryView = button;
我buttonPressed
方法:
- (void)checkButtonTapped:(UIButton *)sender {
UITableViewCell *cell = ((UITableViewCell *)[sender superview]);
NSLog(@"cell row: int%i", [self.tableView indexPathForCell:cell].row);
NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell *)[[sender superview] superview]];
NSLog(@"The row id is %d", indexPath.row);
UIImageView *btnCliked =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_checkmark.png"]];
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[activityView startAnimating];
cell.accessoryView = btnCliked;
}
所有這些代碼的工作在我的其他專用UITableView
頁。
在'tableView:cellForRowAtIndexPath:'中設置按鈕本身的值不是更容易嗎?如果必須,你可以繼承UIButton並添加一個自定義的'NSIndexPath'屬性。看起來比去UIButton的'superview'更容易也更可靠。另外,你可以避免多次調用'tableView:cellForRowAtIndexPath:'。 – mbm29414
@ mbm30075不知道如何在tableView中實現一個子類:cellForRowAtIndexPaht:UIButton ...我想我目前的方式是我的想法...我會嘗試谷歌你的建議。謝謝。 – AhabLives
我猜superview不是你的tableViewCell。試試:'NSLog(@「%@」,[cell class]);'看看你回來了什麼。 – lnafziger