English 中文(简体)
xcode uitableview
原标题:xcode uitableview

i have an array of objects which i am populating in a UItable one of my attributes of each object is a YES/NO value

采用(可调通)表(可调通) 观点小组 ForRowAtIndexPath:NSIndexPath *)indexPath{,以填满我表格如下:

My code creates a table entry for each object in the array. I would like to only populate the table using objects in the array which have the "display" attribute set to YES? how do i do this?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellidentifier = @"customcell";
customcell *cell = (customcell *)[tableView dequeueReusableCellWithIdentifier:
                                  cellidentifier];

my_details *myObj = [appDelegate.myArray objectAtIndex:indexPath.row];

// UITableViewCell cell needs creating for this UITableView row.
if (cell == nil)

{
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"customcell" owner:self options:nil];

    for (id currentObject in topLevelObjects) {
        if ([currentObject isKindOfClass:[customcell class]]) {
            cell = (customcell *) currentObject;
            break;
        }
    }
}


    cell.line1.text = myObj.line1;
    cell.line2.text = myObj.line2;
    cell.line3.text = myObj.line3;


return cell;
}
最佳回答

在将物体送上显示台之前,试图过滤这些物体是一种好的想法。

您可以使用国家定位系统过滤各种物体,并在物体改变状态时,显示特性被确定为是的,重新过滤阵列,并将其传递给表层。

NSPredicate *testForTrue = [NSPredicate predicateWithFormat:@"display == YES"];
NSArray *filteredArray = [myObjectsArray filteredArrayUsingPredicate:testForTrue];

您获得过滤器后 请将此文件通过表格 浏览并告诉它,要重载数据,以便更新。

问题回答

如@Sorin所示,你必须过滤桌子。 可以在表格插入之前或期间这样做。 哪一个是信条问题(以及你通常遵循的方案拟订准则)

a) Before Have all data -> filter -> Have reduced set -> Display reduced table

b) During Have all data -> count #items -> introduce in rows -> Display table For that you have to adapt numberOfRowsInSection (pseudo code!)

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  counter=0;
  for each in table
     if value = YES counter++
  return counter;
}

In the cellForRowAtIndex 现在,你必须跟踪下行,通过全球变量插入:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell;
    static NSString *CellIdentifier = @"Cell";
    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    rowcounter++;
    cell.textLabel.text=[selectionTableArray objectAtIndex:rowcounter];
    return cell;
}




相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签