【发布时间】:2014-02-27 10:00:25
【问题描述】:
当我选择UITableViewCell 时,发生了最奇怪的事情。
如果我选择第一个,它不会做任何事情,但是当我选择第二个时,它会调用 didSelectRowAtIndexPath 方法,但使用第一个的值。
我应该提一下,我使用的是UIViewController,里面有一个UITableView。我还应该提到我刚刚开始使用IOS 7。
这是我的代码。
ChannelsPopoverViewController.h
@interface ChannelsPopoverViewController :UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *channelsTableView;
@end
ChannelsPopoverViewController.m
@implementation ChannelsPopoverViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.channelsTableView.delegate=self;
self.channelsTableView.dataSource=self;
}
-(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"new account cell"];
UIImageView *channelImage=(UIImageView *)[cell viewWithTag:100];
UILabel *cellLabel=(UILabel *)[cell viewWithTag:101];
if (indexPath.row==0) {
channelImage.image=[UIImage imageNamed:@"App-dropbox-icon.png"];
cellLabel.text=@"add dropbox";
}
if (indexPath.row==1) {
channelImage.image=[UIImage imageNamed:@"Google-Drive-icon.png"];
cellLabel.text=@"add google drive";
}
return cell;
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell=(UITableViewCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
UILabel *cellLabel=(UILabel *)[cell viewWithTag:101];
if ([cellLabel.text isEqual:@"add dropbox"]) {
[[DBSession sharedSession] linkFromController:self];
}
}
@end
【问题讨论】:
-
你怎么知道没有加载。尝试添加 NSLog(@"Row: %d", indexPath.row);到 didDeselectRowAtIndexPath:.将 isEqual: 替换为 isEqualToString。
-
你正在使用 didDeselectRowAtIndexPath 或者没有 didSelectRowAtIndexPath
标签: ios objective-c uitableview didselectrowatindexpath