ユーザーがボタン「x」をクリックしたときにUISearchBarからすべてを可変配列に収集したいのですがsearchString
、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:
ああ、私はこれを解決しました!