-3

我正在制作主页包含 TableView 的应用程序,但是当我单击 tableView 中的任何单元格时,我想打开一个 webView,我该如何制作它......这是我的代码以任何方式做我想做的事

我可以更改接口文件或从代码创建 Web 视图或...


@implementation ViewController
@synthesize tblMain, rows, timer;

NSURL *url;
NSString *jsonreturn;
NSData *jsonData;
NSError *error;
NSDictionary *dict;
UITableViewCell *cell;
static NSString *CellIdentifier;

- (void)viewDidLoad{
    [super viewDidLoad];

    [self GetData];
    timer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(GetData) userInfo:nil repeats:YES];
}

-(void)GetData{
    url = [NSURL URLWithString:@"file://localhost/Users/mac/Documents/json.json"];
    jsonreturn = [[NSString alloc] initWithContentsOfURL:url];
    NSLog(jsonreturn);
    jsonData = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding];
    dict = [[[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error] retain];
    rows = [dict objectForKey:@"savola"];
    NSLog(@"Array: %@",rows);
    [self.tblMain reloadData];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [rows count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }

    dict = [rows objectAtIndex: indexPath.row];

    cell.textLabel.text = [NSString stringWithFormat:@"%@ - %@", [dict objectForKey:@"company"], [dict objectForKey:@"price"]];
    cell.detailTextLabel.text = [dict objectForKey:@"time"];

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // open a web view
}


@end
4

2 回答 2

-1

在你在这里发布你的问题之前,做一些最低限度的研究,如果你不明白,来这里发帖,

创建一个新项目->添加一个子类的文件UITableView,现在在didSelectRowAtIndexPath方法内部将其导航到一个新类并在新类中做你的东西(比如加载网络视图,在 xib 中添加一个网络视图)

于 2012-06-26T11:35:22.347 回答
-1

创建一个视图控制器,比如 MyWebviewcontroller 和 xib(在创建视图控制器时检查 xib 的用户界面)。

打开 MyWebViewController.xib 并添加 webview。

然后在 didSelectRowAtIndexPath 中编写代码:

MyWebviewcontroller *viewController =  [[MyWebviewcontroller alloc]initWithNibName:@"MyWebviewcontroller" bundle:nil];
[self.view addSubView:viewController.view];
于 2012-06-26T12:10:30.520 回答