[英]Open new UIView when select a row
I have a problem that is proving difficult to resolve. 我有一个难以解决的问题。
I should open a new UITableView
when clicked a cell in the table above. 单击上表中的单元格时,我应该打开一个新的
UITableView
。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ChoiceChampionViewController *choiceChampionViewController = [[ChoiceChampionViewController alloc] initWithNibName:@"ChoiceChampionViewController" bundle:nil];
NSString * ind = @".....";
NSString * number = ..;
ind = [ind stringByReplacingOccurrencesOfString:@"XX" withString:number];
[[NSUserDefaults standardUserDefaults] setValue:number forKey:@"Region"];
choiceChampionViewController.url = ind;
[self.view addSubview: choiceChampionViewController.view];
}
ChoiceChampionViewController is structured as follows: ChoiceChampionViewController的结构如下:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
champion = [[NSMutableArray alloc] init ];
self.navigationItem.title = @"Here is some text to make the navBar big";
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});
}
- (void)fetchedData:(NSData *)responseData {
Method for process data
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [champion count];
}
- (UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
League * app = [[League alloc] init];
app = [champion objectAtIndex:[indexPath row]];
cell.textLabel.text = app.title;
return cell;
}
But it keeps giving me this error: [ChoiceChampionViewController tableView:cellForRowAtIndexPath:]: message sent to deallocated instance. 但是它一直给我这个错误:[ChoiceChampionViewController tableView:cellForRowAtIndexPath:]:消息发送到已释放实例。 Can we help me?
我们可以帮我吗?
open that new UITableViewController
or UIViewController
with use of pushViewController
for go in to new UIViewController
like bellow... 使用
pushViewController
打开新的UITableViewController
或UIViewController
以便像下面这样进入新的UIViewController
...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;{
ChoiceChampionViewController * choiceChampionViewController = [[ChoiceChampionViewController alloc]initWithNibName:@"ChoiceChampionViewController" bundle:nil];
UIBarButtonItem *_backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleDone target:nil action:nil];
self.navigationItem.backBarButtonItem = _backButton;
[_backButton release],
_backButton = nil;
[self.navigationController pushViewController:choiceChampionViewController animated:YES];
[choiceChampionViewController release];
}
UPDATE : 更新:
also use this bellow structure for cellForRowAtIndexPath:
method... 也将这种波纹管结构用于
cellForRowAtIndexPath:
方法...
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
League * app = [[League alloc] init];
app = [champion objectAtIndex:[indexPath row]];
cell.textLabel.text = app.title;
return cell;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.