NSMuttableArray,TableView,Switch Views以编程方式

时间:2011-10-20 10:00:26

标签: iphone ios

我是Iphone的新程序员......我在我的程序中访问NSMuttable数组时遇到了一些问题......

我在按钮点击时以编程方式生成视图....点击按钮时的代码是

-(IBAction)buttonClicked
    {
    secondView=[[TabBarSearchSecondView alloc]init];
    [myView addSubview:secondView.view];
}

inTabBarSearchSecondView .h文件.....

@interface ......

NSMuttableArray *searchResult;

@end

@property (nonatomic,retain)NSMuttableArray *searchResult;
TabBarSearchSecondView .m文件中的

.........

@synthesize searchResult;


- (void)loadView
{


    CGRect cgRct = CGRectMake(0.0, 0.0, 480, 320); //define size and position of view 

    myView = [[UIView alloc] initWithFrame:cgRct]; //initilize the view    


    //open database

    DbOpenAndClose *dbObject=[[DbOpenAndClose alloc]init];
    [dbObject openDatabase];


    //for call of search showroom

    SearchProduct *object=[[SearchProduct alloc]init];

    searchResult=[object searchShowrooms:productname:cityname];

    [dbObject closeDatabase];


        count=[searchResult count];/// print 3 because 3 record match in database


    UITableView *table=[[UITableView alloc]initWithFrame:CGRectMake(4,80,312,325)        style:UITableViewStylePlain];

    //table.delegate=self;

    table.dataSource=self;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    //NSLog(@"%i", [searchResult count]);

    return [searchResult count]; ///Not accessible here...Application Crash Here...
}

感谢您为我的代码提供宝贵的时间......先谢谢

1 个答案:

答案 0 :(得分:1)

您必须保留 searchResult数组....

在此代码之后

    searchResult=[object searchShowrooms:productname:cityname];

保留searchResult。否则发布 .. 保留 searchResult就像这样。

[searchResult retain];