내 UIViewController
안에 UITableView
이 있습니다. 데이터, 자막 데이터 및 액세서리 버튼은 모두로드가 잘됩니다. 그러나 액세서리 버튼을 누르면 모두 인덱스 0이 반환됩니까? dataSource
및 delegate
은 .xib의 File 's Owner에 연결되어 있습니다. 무엇이 누락 되었습니까?단추가 포함 된 테이블보기 셀에 항상 인덱스가있는 것 같습니다.
헤더 파일 :
@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에 하위 클래스를 구현하는 방법을 잘 모르겠습니다 ... 내 현재 방식이 내가 생각했던 것 같아요 ... 나는 당신의 제안을 Google에 시도 할 것입니다. 고마워. – AhabLives
superview가 tableViewCell이 아닌 것 같습니다. 시도해보십시오 :'NSLog (@ "% @", [셀 클래스]); 그리고 당신이 무엇을 얻고 있는지보십시오. – lnafziger