ios - 如何将 uitableview 中的单个单元格链接到不同的 URL?

标签 ios objective-c wordpress uitableview

目前我的 uitablview 中有两个独立的标题数组。每个数组都分组在它自己的部分中。例如。第 1 部分(item1、item2、item3) 第 2 部分(item1、item2 等)。我想将每个单元格链接到某个 wordpress 帖子。我该怎么做?我在包含数组的 viewdidload 方法下方链接了我的所有代码。

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return numberOfSections;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    switch (section) {
        case manualSection:
            return [self.manual count];
        case interviewSection:
            return [self.interviews count];
        default:
            return 0;
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath         *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier     forIndexPath:indexPath];

    switch (indexPath.section)
    {
        case manualSection:
            cell.textLabel.text = [self.manual objectAtIndex:indexPath.row];
            break;
        case interviewSection:
            cell.textLabel.text = [self.interviews objectAtIndex:indexPath.row];
            break;
        default:
            cell.textLabel.text = @"Not Found";
    }
    return cell;

}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    switch (section) {
        case manualSection:
            return @"Manual";
            break;
        case interviewSection:
            return @"Interviews";
            break;
        default:
            return 0;
    }

最佳答案

  • 使用您需要的属性创建模型(标题、链接)
  • 使用模型而不是字符串更新数组(手册、访谈)
  • 在您向我们展示的类中实现 -tableView:didSelectRowAtIndexPath: 函数,以访问您需要的索引处的列表;然后获取模型并访问链接

NSURL *url = [NSURL URLWithString:@"http://www.stackoverflow.com/"];
if( ![[NSWorkspace sharedWorkspace] openURL:url] )
    NSLog(@"Failed to open url: %@",[url description]);

关于ios - 如何将 uitableview 中的单个单元格链接到不同的 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25903405/

相关文章:

ios - 在 iPhone/iPad 应用程序中保存用户设置

iphone - 在 iPhone 上的 UIWebView 中显示文档目录中的本地 HTML 文件

mysql - 根据另一个字段的值在特定字段中替换 MySQL 中的字符串

html - 中心列大小 - 在调试中调整大小,但找不到后端代码

ios - 在 parent 中实现 child 代表?

objective-c - iPad 模拟器和设备之间 NSDateFormatter 的区别

ios - phonegap iphone : Documents Directory Absolute path

iphone - 在某个时间创建表示 "today"的 NSDate 对象

objective-c - 将数字格式化为字符串时,请删除整数

php - 导出到 csv wordpress