i’m making app that the main page include TableView but i want when i click in any cell in the tableView open a webView, how can i make it …
this is my code any way to do what i want
can i change the interface file or create a web view from the code or …
@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
Before u post your question here ,do some minimum research, though if u dont get,come n post here ,
Create a new project–> add a file which is subclass of
UITableView, now insidedidSelectRowAtIndexPathmethod navigate it to a new class and do your stuffs in the new class (like loading web view, add a web view in xib)