ios - UITableView 混合部分项目

标签 ios uitableview

我试图从我的表格 View 的前 2 个部分中打开 2 个不同的 View Controller ,并从其他 4 个部分中打开一些 URL。第一部分不执行任何操作,其他部分混淆,并且用于打开 URL 的部分不起作用。感谢您的回复。

@implementation SettingsViewController {
NSArray * sectionheaderArr;
}
- (void)viewDidLoad
{

sectionheaderArr = [[NSArray alloc]initWithObjects:NSLocalizedString(@"fb",  
nil),NSLocalizedString(@"recommend", nil),NSLocalizedString(@"feedback", 
nil),NSLocalizedString(@"rate", nil),NSLocalizedString(@"language", 
nil),NSLocalizedString(@"all_providers", nil), nil];
[super viewDidLoad];
// Do any additional setup after loading the view.
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: 
(NSInteger)section{
return sectionheaderArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath {

static NSString *CellIdentifier =@"Cell";
int row = indexPath.row;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault   
reuseIdentifier:CellIdentifier];

}
cell.textLabel.text = [sectionheaderArr objectAtIndex:row];

return cell;
}



-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath   
*)indexPath{
if (indexPath.section == 0) {
    if (indexPath.row ==0){
        [self performSegueWithIdentifier:@"openFacebook" sender:self];
    }
}
if (indexPath.section ==1) {
  if (indexPath.row ==1) {
    [self performSegueWithIdentifier:@"opentest" sender:self];
  }
}

if (indexPath.section==2) {
    if (indexPath.row ==2) {
        UIApplication*app1 = [UIApplication sharedApplication];
        NSString*path = @"http://www.google.de";
        NSURL*myurl = [NSURL URLWithString:path];
        [app1 openURL:myurl];
    }

}
}

最佳答案

这是您问题的答案:

@implementation SettingsViewController {
NSArray * sectionheaderArr;
}
- (void)viewDidLoad
{

sectionheaderArr = [[NSArray alloc]initWithObjects:NSLocalizedString(@"fb",  
nil),NSLocalizedString(@"recommend", nil),NSLocalizedString(@"feedback", 
nil),NSLocalizedString(@"rate", nil),NSLocalizedString(@"language", 
nil),NSLocalizedString(@"all_providers", nil), nil];
[super viewDidLoad];
// Do any additional setup after loading the view.
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: 
(NSInteger)section{
return sectionheaderArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath {

static NSString *CellIdentifier =@"Cell";
int row = indexPath.row;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault   
reuseIdentifier:CellIdentifier];

}
cell.textLabel.text = [sectionheaderArr objectAtIndex:row];

return cell;
}



-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath   
*)indexPath{

    if (indexPath.row ==0){
        [self performSegueWithIdentifier:@"openFacebook" sender:self];
    }


  if (indexPath.row ==1) {
    [self performSegueWithIdentifier:@"opentest" sender:self];
  }



    if (indexPath.row ==2) {
        UIApplication*app1 = [UIApplication sharedApplication];
        NSString*path = @"http://www.google.de";
        NSURL*myurl = [NSURL URLWithString:path];
        [app1 openURL:myurl];
    }


}

请注意,在您实现“didDeselectRowAtIndexPath”时,我还更改了“didSelectRowAtIndexPath”方法,因此在您取消选择单元格之前该方法不会起作用。

也感谢@iphonic 的解释。

关于ios - UITableView 混合部分项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24361236/

相关文章:

ios - 等待 NSURLSessionTask 完成

ios - 在 websocket/SignalR 响应中获取 "\n "?

swift - UIBarButtonItem 操作不工作 UITableView 单元格

ios - 拍照并存储在 Xamarin.iOS 中的自定义相册中

ios - 苹果 map 上的简单标记聚类

ios - 如何将步进值传递给 ViewController?

iphone - uitableviewcell 上的附件勾选在某些情况下不显示

ios - 滚动后使用可重复使用的单元格与 uitableview 单元格的内容重叠

ios - 如何在 iPhone 中使用 Base64 解码字符串

ios - 无法确定表格 View 单元格的宽度