【问题标题】:SearchBar does not work anymore after adding new objects添加新对象后,SearchBar 不再起作用
【发布时间】:2012-03-31 12:15:46
【问题描述】:

我在我的应用程序中集成了一个搜索栏。它工作得很好。但是在向我的 tableView 添加新元素后,我的 searchBar 不再起作用。我在此代码块中收到错误消息:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; // Here i get: >Control reaches end of non void function<

if (cell == nil) 
{
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
if (searching)
{
    VerwaltungInformation *searchedFormel = [copyListOfFormularies objectAtIndex:indexPath.row] ; //Here i get: >Thread 1: Program received signal "SIGABRT"<

    cell.textLabel.text = searchedFormel.nameFormel;
}
else
{
NSDictionary *dictionaryCell = [listOfFormularies objectAtIndex:indexPath.section];
NSArray *arrayCell = [dictionaryCell objectForKey:@"Formel"];

VerwaltungInformation *cellValue = [arrayCell objectAtIndex:indexPath.row];

cell.textLabel.text = cellValue.nameFormel;
}

return cell;

cellIdentifier 似乎有问题 - 但我无法弄清楚。

感谢您的帮助!

【问题讨论】:

    标签: iphone objective-c cell searchbar


    【解决方案1】:

    警告Control reaches end of non void function 出现在您结束non void 方法而不返回对象时。要找出您的问题,请右键单击鼠标选择Structure 选择Re – Indent。现在您可以更轻松地找出代码的结构并找出发生了什么。

    【讨论】:

      【解决方案2】:

      我怀疑问题可能出在源文件的早期,高于您发布的方法。请试试这个:

      第 1 步:

      @implementation MyClass
      
      @synthesize ...
      
      #if 0
      
      // all of the code that precedes cellForRowAtIndexPath
      
      #endif
      
       - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      
      // and so on
      

      编译器是否仍然对 CellIdentifier 发出警告?我的猜测是否定的(尽管您可能会在下面看到各种错误,这些错误与您隐藏在 #if #endif 中的符号有关)。

      第 2 步:

      移动#if #endif 对,以逐个方法在文件中包装方法,从您发布的方法上方的方法开始,直到再次出现 CellIdentifier 警告。当它发生时,您就会找到问题的根源。

      【讨论】:

      • 但我不明白为什么在添加新元素后 searchBar 不再工作了...... PS:我是 Objective-c 的新手......我真的无法理解你的意思......
      • 您是否看到编译器错误(如代码中的注释所示),或者您是否能够运行应用程序但它的行为与预期不符?
      猜你喜欢
      • 2014-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-29
      相关资源
      最近更新 更多