【发布时间】:2013-12-05 13:55:19
【问题描述】:
过去几天我正在处理一个问题。我在 xib 文件中有一个 UIScrollView,在这个 UIScrollView 中我放了 UIViews(也作为 xib),在 UIViews 中我放了 UITableViews(也作为 xib)。但是作为一个菜鸟,我总是使用 cellForRowAtindexPath 填充我的 UITableView,你用你想要的文本返回单元格,这一切都完成了,但是这次它没有被调用,所以也许还有另一种填充它的方法?作为信息,我正在尝试使用 CollapseClick 作为我的视图。如果有人可以帮助我或者对如何填充它有任何想法,请随时回答。
这是我的代码,我省去了所有的 xml 解析过程。 .m 是我初始化我的 UITableView
- (void)viewDidLoad
{
[super viewDidLoad];
newsTable = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewCellStyleDefault];
newsTable.delegate = self;
//newsTable.dataSource = self;
myCollapseClick.CollapseClickDelegate = self;
[myCollapseClick reloadCollapseClick];
// If you want a cell open on load, run this method:
[myCollapseClick openCollapseClickCellAtIndex:0 animated:YES];
/*
// If you'd like multiple cells open on load, create an NSArray of NSNumbers
// with each NSNumber corresponding to the index you'd like to open.
// - This will open Cells at indexes 0,2 automatically
NSArray *indexArray = @[[NSNumber numberWithInt:0],[NSNumber numberWithInt:2]];
[myCollapseClick openCollapseClickCellsWithIndexes:indexArray animated:NO];
*/
}
我是否需要返回带有 UITable 视图的 UIViews
-(UIView *)viewForCollapseClickContentViewAtIndex:(int)index {
switch (index) {
case 0:
return test1View;
break;
case 1:
return test2View;
break;
case 2:
return test3View;
break;
default:
return test1View;
break;
}
}
好旧的 cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
CGRect frame = CGRectMake(0, 0, 300, 50);
UILabel *lbl1 = [[UILabel alloc] initWithFrame:frame];
lbl1.textAlignment = NSTextAlignmentCenter;
[lbl1 setFont:[UIFont fontWithName:@"Helvetica" size:12.0]];
//self.tableView.separatorColor = [UIColor whiteColor];
//lbl1.backgroundColor = [UIColor purpleColor];
[lbl1 setTextColor:[UIColor blackColor]];
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
if (storyIndex == 0 && FlagS)
{
NSMutableArray * SIR = [[NSUserDefaults standardUserDefaults] objectForKey:@"sizingSheet"];
NSString * SID = [[SIR objectAtIndex: storyIndex] objectForKey: @"sizing_id"];
NSString *DID = [[SIR objectAtIndex: storyIndex] objectForKey: @"data_id"];
Request = [[restRequestManager alloc]init];
NSString *SDD = [NSString stringWithFormat:@"%@%@%@%@%@", @"sizing_id=", SID, @"&", @"data_id=", DID];
NSData* Mimage = [Request restTestRequesterImage:@"http://www.stackoverflow.com" serviceUri:@"question/Post" parameters:SDD technique:@"POST"];
cell.imageView.image = [UIImage imageWithData:Mimage];
return cell;
}
searchString = @"TH_MEASURE_CATEGORY_";
str=[category objectAtIndex:storyIndex];
NSArray *array = [[NSMutableArray alloc]init];
array = [str componentsSeparatedByString:@"@"];
for (NSString *tempStr in array) {
NSComparisonResult result = [tempStr compare:searchString options:(NSCaseInsensitiveSearch) range:NSMakeRange(0, [searchString length])];
if (result == NSOrderedSame) {
lbl1.text = [category objectAtIndex: storyIndex];
lbl1.text = [lbl1.text substringFromIndex: MIN(20, [lbl1.text length])];
[cell.contentView addSubview:lbl1];
}
else{
lbl1.text = [category objectAtIndex: storyIndex];
[cell.contentView addSubview:lbl1];
}
}
return cell;
}
和没有所有无用内容的 .h
@interface MeasuresViewController: UIViewController <CollapseClickDelegate,UITextFieldDelegate, UITableViewDelegate, UITableViewDelegate> {
IBOutlet UIView *test1View;
IBOutlet UIView *test2View;
IBOutlet UIView *test3View;
__weak IBOutlet CollapseClick *myCollapseClick;
IBOutlet UITableView * newsTable;
BOOL *FlagS;
UIActivityIndicatorView * activityIndicator;
CGSize cellSize;
NSMutableArray * stories;
NSMutableString * currentCategory, * currentSubcategory, * currentValue, * currentName, * currentSrc;
NSDictionary *data, *data1, *data2, *data3, *data4;
}
- (void)parseXMLFileAtURL:(NSString *)URL;
-(BOOL)ifStringExists:(NSString *)stringSentToCheck selectYourCheckArray:(NSMutableArray *)SelectedArray;
@property (nonatomic, strong) NSMutableArray *photos;
@property (atomic, strong) NSMutableArray *assets;
@end
【问题讨论】:
-
你设置了tableview委托和数据源方法吗??或在xib中设置链接。
-
代表像您在 .h 中声明的代表?我现在用 .h 编辑。
-
/
/newsTable.dataSource = self;???删除评论 -
几秒钟前做的,没有任何反应仍然忽略它,我收到一个警告,它说从不兼容的类型“MeasuresViewController“const_strong”分配给“id
”。是否必须在 UITableViewController 类中声明 cellForRowAtIndexPath 才能工作?
标签: ios objective-c uitableview uiview uiscrollview