在接口文件中定义了两个数组,是weak的,用数组的值给tableview后,然后进行点击,提示对应数组的值时,提示为空,改为strong则不为空。具体操作代码如下:
#import "MySecondController.h"@interface MySecondController ()@end@implementation MySecondController- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(doleft)];
self.navigationItem.leftBarButtonItem = leftButton;
//定义数组
self.books=[NSArray arrayWithObjects:@"123",@"456",@"789",@"012",@"345",@"678",nil];
NSLog(@"saaaaaa%@",self.books);
//定义描述
self.details=@[@"abcc",@"efg",@"hij",@"lmn",@"wgth",@"jio"];
self.content_tableview.dataSource=self;
self.content_tableview.delegate=self;
}- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//返回上一页
-(void)doleft{
[self.navigationController popViewControllerAnimated:YES];
}/*
#pragma - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*///该方法的返回值决定各表格行的控件
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * cellId=@"cellId";
UITableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil) {
switch (indexPath.row%3) {
case 0:
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId];
break;
case 1:
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
break;
case 2:
cell=[[UITableViewCell alloc ] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
break;
default:
break;
}
}
NSUInteger rowNo=indexPath.row;
cell.textLabel.text=[self.books objectAtIndex:rowNo];
cell.detailTextLabel.text=[self.details objectAtIndex:rowNo];
return cell;
}- (NSInteger ) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.books.count;
}//点击每行触发的方法 可以触发
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger rowNo11=indexPath.row;
NSString* item_name = [ self.books objectAtIndex:rowNo11];
NSLog(@"ssssss%@",self.books);
UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:item_name delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alter show];
}
@end
这是为什么啊?
#import "MySecondController.h"@interface MySecondController ()@end@implementation MySecondController- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(doleft)];
self.navigationItem.leftBarButtonItem = leftButton;
//定义数组
self.books=[NSArray arrayWithObjects:@"123",@"456",@"789",@"012",@"345",@"678",nil];
NSLog(@"saaaaaa%@",self.books);
//定义描述
self.details=@[@"abcc",@"efg",@"hij",@"lmn",@"wgth",@"jio"];
self.content_tableview.dataSource=self;
self.content_tableview.delegate=self;
}- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//返回上一页
-(void)doleft{
[self.navigationController popViewControllerAnimated:YES];
}/*
#pragma - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*///该方法的返回值决定各表格行的控件
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * cellId=@"cellId";
UITableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil) {
switch (indexPath.row%3) {
case 0:
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId];
break;
case 1:
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
break;
case 2:
cell=[[UITableViewCell alloc ] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
break;
default:
break;
}
}
NSUInteger rowNo=indexPath.row;
cell.textLabel.text=[self.books objectAtIndex:rowNo];
cell.detailTextLabel.text=[self.details objectAtIndex:rowNo];
return cell;
}- (NSInteger ) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.books.count;
}//点击每行触发的方法 可以触发
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger rowNo11=indexPath.row;
NSString* item_name = [ self.books objectAtIndex:rowNo11];
NSLog(@"ssssss%@",self.books);
UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:item_name delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alter show];
}
@end
这是为什么啊?
http://blog.sina.com.cn/s/blog_a841894b0101e839.html
虽然赋值了 self.books=[NSArray arrayWithObjects:@"123",@"456",@"789",@"012",@"345",@"678",nil];
但是随后又释放掉了。