我建立基於一個陣列內的數據的應用程序IOS - 我與濾波數據掙扎到行 - 我的陣列的一個片段是如下 -濾波陣列段
陣列數據/陣列 -
sightsObject *sight2 = [[sightsObject alloc] initWithsiteTitle:@"The Beatles Homes" siteSection:@"beatles" siteType:@"Take a glimpse of the fab 4's childhood homes.." siteSubTitle:@"" siteDescription:@"" siteMapUrl:@"" sitePic:@"fabs"];
sightsObject *sight3 = [[sightsObject alloc] initWithsiteTitle:@"The Beatles Gig Venues" siteSection:@"beatles" siteType:@"" siteSubTitle:@"Its not all about the Cavern..." siteDescription:@"" siteMapUrl:@"" sitePic:@"fabs"];
sightsObject *sight4 = [[sightsObject alloc] initWithsiteTitle:@"The Beates Locations" siteSection:@"beatles" siteType:@"" siteSubTitle:@"Stawberry Fields, Penny Lane, Palm House..." siteDescription:@"" siteMapUrl:@"docks" sitePic:@"fabs"]
sightsObject *sight5 = [[sightsObject alloc] initWithsiteTitle:@"Albert Dock" siteSection:@"dock" siteType:@"" siteSubTitle:@"" siteDescription:@"" siteMapUrl:@"" sitePic:@""];
sightsObject *sight6 = [[sightsObject alloc] initWithsiteTitle:@"Keiths Wine Bar" siteSection:@"Restaurants" siteType:@"" siteSubTitle:@"Classic Eatery on Lark Lane" siteDescription:@"" siteMapUrl:@"" sitePic:@""];
self.sightsArray = [NSArray arrayWithObjects: sight2, sight3, sight4, sight5, sight6,nil];
SightsObject.H 用於SightsObject OS頁眉如下 -
#import <Foundation/Foundation.h>
@interface sightsObject : NSObject
@property(strong)NSString *siteTitle;
@property(strong)NSString *siteSection;
@property(strong)NSString *siteType;
@property(strong)NSString *siteSubTitle;
@property(strong)NSString *siteDescription;
@property(strong)NSString *siteMapUrl;
@property(strong)UIImage *sitePic;
-(id)initWithsiteTitle:(NSString *)siteTitleD siteSection:(NSString *)siteSectionD siteType:(NSString *)siteTypeD siteSubTitle:(NSString *)siteSubTitleD siteDescription:(NSString *)siteDescriptionD siteMapUrl:(NSString *)siteMapUrlD sitePic:(NSString *)sitePicD;
@end
ROWS 我不確定如何計算數據行的,適用於每個部分的金額 - 所以這是目前硬編碼 -
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 8;
}
過濾數據加入表格單元格
我的問題是我現在不知道如何將數據過濾到行中 - 我目前有下面的代碼(在我的tableview中有兩種單元格類型) - 運行時代碼在正確的單元格中顯示相關數據 - 但爲每個部分重複相同的數據 - 我如何正確地過濾它?
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier [email protected]"sightsCell";
static NSString *CellIdentifierH [email protected]"headerCell";
NSString * intro = @"intro";
NSString * ArtNoP = @"lower";
sightsObject *b = [self.sightsArray objectAtIndex:indexPath.row];
tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
UITableViewCell *cell;
if ([b.siteSection isEqualToString:intro]) {
cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifierH forIndexPath:indexPath];
HeaderCell *cellHead = (HeaderCell *)cell;
cellHead.selectionStyle = UITableViewCellSelectionStyleNone;
cellHead.sightsText.text = b.siteTitle;
cellHead.textLabel.backgroundColor=[UIColor clearColor];
return cellHead;
}
else{
cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
sightsCell *cellSights = (sightsCell *)cell;
cellSights.selectionStyle = UITableViewCellSelectionStyleNone;
cellSights.sightsTitle.text = b.siteTitle;
cellSights.sightsSubTitle.text = b.siteSubTitle;
cell.textLabel.backgroundColor=[UIColor clearColor];
return cellSights;
}
}
什麼是「正確的」?從你的源數據來看,應該在哪裏?顯示您的'sightsObject'類的標題。 – Wain
Hi @Wain Header added above - 我的意思是我在表格中有兩個自定義類 - 我通過上面的if語句進入 - 這部分工作正常 - 我的問題是它顯示了一系列帶有部分頭和每個相同的數據 - 我想能夠過濾數據到部分 - 然後決定它應該出現在哪個自定義單元格 – Dancer
而且重要的一塊信息是「siteSection」在當前在你的景點陣列中的每個對象陣列'?介紹項目從哪裏來?爲什麼不在'indexPath.row == 0'時添加簡介部分? – Wain