当用户单击按钮“x”到可变数组时,我想searchString
从 UISearchBar 收集所有内容,但是它没有被添加到 self.historyList 中......
在方法中:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchString
{
self.ss = searchBar.text;
//this is initialized in viewDidLoad method
//self.addSSFort = [[NSMutableArray alloc]init];
[self.addSSFort addObject: self.ss];
NSLog (@"addSSFort contains %@", self.addSSFort);
//NSMutableArray *historyList = [[[NSMutableArray alloc]init]retain];
//this one is initialized in viewDidLoad method
//self.historyList = [[NSMutableArray alloc]init];
if ([self.ss length] == 0)
{
// here it is never being added
[self.historyList addObject:[self.addSSFort objectAtIndex:[self.addSSFort count]-1]];
}
}
编辑 :
self.addSSFort contains:
x
xc
xco
xcod
xcode <- I want to add this to self.historyList
""
t
tr
tre
tree <- I want to add this to self.historyList
""
但 self.historyList 包含:
""
""
我希望它包含:
xcode
tree
我使用这个语句if ([self.ss length] == 0)
,因为它告诉我用户点击了“x”来删除 searchString,并告诉我他/她已经完成了当前的 searchString。我知道 ARC,但我是为 iOS 3 > iOS 5 的用户这样做的。
编辑2:
啊,我已经解决了这个问题!