如何显示数组中的数据

时间:2011-06-14 09:33:25

标签: iphone

// Take an array to store all string.
NSMutableArray *allRows = [[[NSMutableArray alloc] init] autorelease];

while(sqlite3_step(statement) == SQLITE_ROW)
    {   
        char *field1 = (char *) sqlite3_column_text(statement,0);
        NSString *field1Str = [[NSString alloc] initWithUTF8String: field1];
        char *field2 = (char *) sqlite3_column_text(statement,1);
        NSString *field2Str = [[NSString    alloc] initWithUTF8String: field2];

        NSString *str = [NSString stringWithFormat:@"%@::%@",field1Str, field2Str];
        // textv.text=str; // I don't know why your are mixing your view controller stuff's in database function.
// Add the string in the array.
allRows addObject:str];

        [field1Str release];
        [field2Str release];
        }

// Finally you can return your allRows
return allRows;

现在好了如何显示该数组的数据

3 个答案:

答案 0 :(得分:0)

我认为这是你想要的东西......

for(int i=0;i< allRows.count;i++)
{
[allRows objectAtIndex:i];
}

答案 1 :(得分:0)

for (int index=0; index<[allRows count]; index++) {
            NSString *retrievedString=[allRows objectAtIndex:index];
//use retrievedString and display it in label kinda thing
    }

答案 2 :(得分:0)

如果要在UITableview中显示,请执行以下操作。

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    {
    return [allRows count];
    }     


     - (UITableViewCell *)tableView:(UITableView *)tablefirst cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        [allRows objectAtIndex:i];

        }