我一直在尝试将简单的搜索功能添加到我的应用程序中的TableViewController.我按照Ray Wenderlich的教程.我有一个带有一些数据的tableView,我在storyboard中添加了搜索栏+显示控制器,然后我有了这段代码:
#pragma mark - Table View
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BreedCell" forIndexPath:indexPath];
//Create PetBreed Object and return corresponding breed from corresponding array
PetBreed *petBreed = nil;
if(tableView == self.searchDisplayController.searchResultsTableView)
petBreed = [_filteredBreedsArray objectAtIndex:indexPath.row];
else
petBreed = [_breedsArray objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = petBreed.name;
return cell;
}
#pragma mark - Search
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
[_filteredBreedsArray removeAllObjects];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.name contains[c] %@",searchString];
_filteredBreedsArray = [[_breedsArray filteredArrayUsingPredicate:predicate] mutableCopy];
return YES;
} …Run Code Online (Sandbox Code Playgroud) 我不能,为了我的生活,成功运行"宝石安装节俭",在构建宝石的原生扩展时,事情就失败了; 这是输出:
(acib708) ~ -> gem install thrift
Building native extensions. This could take a while...
ERROR: Error installing thrift:
ERROR: Failed to build gem native extension.
/Users/acib708/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
extconf.rb:25:in `<main>': Use RbConfig instead of obsolete and deprecated Config.
extconf.rb:25:in `<main>': Use RbConfig instead of obsolete and deprecated Config.
checking for strlcpy() in string.h... yes
creating Makefile
make "DESTDIR="
compiling binary_protocol_accelerated.c
compiling bytes.c
compiling compact_protocol.c
compiling memory_buffer.c
compiling protocol.c
compiling strlcpy.c
^
Run Code Online (Sandbox Code Playgroud)
(......)
In file included from strlcpy.c:20:
./strlcpy.h:28:15: error: …Run Code Online (Sandbox Code Playgroud) 进入bash,我喜欢它,但似乎有很多细微之处最终会在功能方面产生很大的不同,不管怎么说,这就是我的问题:
我知道这有效:
total=0
for i in $(grep number some.txt | cut -d " " -f 1); do
(( total+=i ))
done
Run Code Online (Sandbox Code Playgroud)
但为什么不呢?:
grep number some.txt | cut -d " " -f 1 | while read i; do (( total+=i )); done
Run Code Online (Sandbox Code Playgroud)
some.txt:
1 number
2 number
50 number
Run Code Online (Sandbox Code Playgroud)
for和while循环分别接收1,2和50,但for循环显示总变量最终为53,而在while循环代码中,它只保持为零.我知道我缺少一些基本知识,请帮助我.
我也没有得到管道的差异,例如,如果我跑
grep number some.txt | cut -d " " -f 1 | while read i; echo "-> $i"; done
Run Code Online (Sandbox Code Playgroud)
我得到了预期的输出
-> 1
-> 2
-> 50
Run Code Online (Sandbox Code Playgroud)
但如果这样跑的话
while read i; echo …Run Code Online (Sandbox Code Playgroud)