这个应用程序是一个带有标签栏控制器的表视图。我正在记录数组的数量:arrayOfFavourites,即使我添加一个对象仍然有一个零值,我的相关代码,显示的所有对象在代码中分配和初始化(先前或现在),一些是实例,一些是属性:addObject:要数组不工作(数组仍然没有)
ListViewController.m:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"TOUCHED CELL!");
// Push the web view controller onto the navigation stack - this implicitly
// creates the web view controller's view the first time through
[[self navigationController] pushViewController:webViewController animated:YES];
// Grab the selected item
entry = [[channel items] objectAtIndex:[indexPath row]];
if (!entry) {
NSLog(@"!entry");
}
// Construct a URL with the link string of the item
NSURL *url = [NSURL URLWithString:[entry link]];
// Construct a request object with that URL
NSURLRequest *req = [NSURLRequest requestWithURL:url];
// Load the request into the web view
[[webViewController webView] loadRequest:req];
// Take the cell we pressed
// IMPORTANT PART
CELL = [tableView cellForRowAtIndexPath:indexPath];
[webViewController setItem:entry];
webViewController = nil;
webViewController = [[WebViewController alloc] init];
[entry release];
}
WebViewController.m:
你摇到最喜欢的一个单元
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
cellToPassOn = nil;
NSLog(@"Favouriting"); // YES I KNOW SPELLING
// This is pretty simple, what we do is we take the cell we touched and take its title and link
// then put it inside an array in the Favourites class
Favourites *fav = [[Favourites alloc] init];
ListViewController *list = [[ListViewController alloc] init];
[self setCellToPassOn: [list CELL]];
if (!item) {
NSLog(@"NILLED ITEM");
}
[[fav arrayOfFavourites] addObject:[item autorelease]];
[fav setCell: cellToPassOn];
[fav release];
[list release];
item = nil;
}
Favourites.m:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
arrayOfFavourites = [[NSMutableArray alloc] init];
NSLog(@"ROWS NO.");
NSLog(@"%i", [arrayOfFavourites count]);
return [arrayOfFavourites count];
}
这也可能是另一个有关内存泄漏的问题。 – 2011-12-19 12:32:15
我把分配和初始化在initWithStyle:方法,但仍然无法正常工作...我分析没有内存泄漏! – user973985 2011-12-19 12:39:51
何时motionBegan:withEvent:被调用?表重新加载后?移动数组的初始化以查看是否加载,并在将对象添加到数组后重新加载表 – 2011-12-19 12:54:49