我正在搜索实现一个从网址检索信息的UISearchbar,并使用默认方法:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
Run Code Online (Sandbox Code Playgroud)
我可以立即检测文本何时更改并执行url的获取,但是这样,文本类型很慢,因为iPhone正在搜索url,所以我想在用户停止写入时开始获取url第二,所以我想检测打字的暂停,以刷新通过网址检索信息的表格视图.我找到了这个请求的旧帖子,我尝试了一个解决方案,对我来说不起作用:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(request:) object:searchText];
//.....
[self performSelector:@selector(request:) withObject:searchText afterDelay:1.5];
}
-(void)request:(NSString *)myString
{
NSLog(@"%@",myString);
}
Run Code Online (Sandbox Code Playgroud)
这样当我输入请求方法时,我没有调用,但是当我停止输入时,我为每个输入的字符调用它,所以默认方法是一样的,我错了什么?或者实施不正确?
我认为这是一个相当复杂的问题.我有一个显示许多可下载内容的TableView.当您在单元格中的按钮上单击它时,下载开始.
但我有几个问题:1.如何确保progressBar将一直显示(即使用户滚动滚动并重新加载单元格)2.如何确保用户可以下载一次2个文件.我担心它会导致问题,因为我使用了一些实例Variables.在某种程度上它应该有点像在音乐应用程序中从iCloud下载
这是我的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
}
//cell.tag = indexPath.row*10;
Uebungsblaetter *uebungCell = [uebungsblattArray objectAtIndex:indexPath.row];
cell.tag = indexPath.row*10;
cell.textLabel.text = [self getFileNameOutOf:uebungCell.url];
cell.textLabel.textColor = [UIColor grayColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIButton *dl = [UIButton buttonWithType:UIButtonTypeCustom];
dl.tag = indexPath.row*10;
[dl setBackgroundImage:[UIImage imageNamed:@"downloadButton.png"] forState:UIControlStateNormal];
[dl setBackgroundImage:[UIImage imageNamed:@"downloadButtonH.png"] forState:UIControlStateHighlighted];
[dl setFrame:CGRectMake(230.0, (cell.frame.size.height-28)/2, 28, 28)];
[dl addTarget:self action:@selector(downloadFileWhenPressedButton:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView …Run Code Online (Sandbox Code Playgroud) 我仍然是对象c的新手,所以如果这是一个菜鸟问题,请跟我说.我正在尝试使用相应的对象信息设置我的navigationcontroller的标题.我正在使用prepareforsegue,但第一次是segue到新的控制器,标题是空白的.如果我再次尝试,它会显示,但如果我按下其他内容,它会显示我之前按下的内容的标题.我在下面嵌入了我的代码.
//.h
#import <UIKit/UIKit.h>
@interface STATableViewController : UITableViewController
@property(strong,nonatomic)NSArray *listOfExercises;
@property(weak,nonatomic)NSString *navTitle;
@end
//.m
#import "STATableViewController.h"
#import "ExercisesViewController.h"
@implementation STATableViewController
@synthesize listOfExercises = _listOfExercises, navTitle = _navTitle;
- (void)viewDidLoad
{
[super viewDidLoad];
_listOfExercises = [NSArray arrayWithObjects:@"Raketstart",@"SpeedBåd",@"Træstamme",nil];
self.navigationItem.title = @"Exercises";
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [_listOfExercises count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) { …Run Code Online (Sandbox Code Playgroud)