Arg*_*ent 3 iphone xcode objective-c uitableview ios
更新2:
长话短说,我对此很愚蠢(而且,在我的辩护中,没有得到适当的教育).它现在有效.我的问题已经脱离了原来的主题一点点,但那是因为我不理解我的应用程序中发生了什么.我想用最后一个(和小的)查询来关闭这个问题:
我的customCell.xib中有两个标签.我希望其中一个(cell.label2)有时包含更长的文本段(2-3行).我知道一种使它完全适合的方法是设置自动收缩属性,但缩小到文本,以便它可以适合单行.我希望保留原始文本大小并扩展单元格的高度,使文本跨越多行而不是缩小它.
有没有办法做到这一点?
更新1:
我根据下面的回复尝试了一些事情,他们让我无处可去.我越来越相信我做了一些根本错误的事情,而你们只是想不到它,因为它是如此基本.所以让我们再试一次.我要稍微更改名称,以便更容易记住.
问题似乎在于我无法创建任何IBOutlets或IBActions我的customCell.现在我有3个文件应该处理这个(DetailedDirectionViewCell.{h,m,xib},但是Interface Builder不允许我在UITableViewCell任何地方创建一个属性/出口/引用.
我没有在这里复制代码,而是提供了一个带有我代码链接的PasteBin条目.和以前一样,我删除了不那么有趣的方法.看看你会不会. http://pastebin.com/p4eADhKQ
我也有customCell.{h,m},但这些只是继承自的新的Objective C类文件UITableViewCell.customCell.xib只是一个有两个标签的单元格.
所以我真的有几个问题.
首先,UITableView使用UITableViewCell自己的.XIB文件中包含的自定义以编程方式生成.我的DirectionsViewController类只是一个UITableView程序化单元格.点击其中一个单元格需要提供DetailedDirectionsViewController表(以模态方式),其单元格设计位于DetailedDirectionsViewCell.xib文件中.问题是,我不能创建一个IBOutlet用于UITableViewCell从笔尖文件-任何地方.拖动文件的所有者图标/插座不提供任何创建.经过5个小时的挣扎,这意味着我无法展示我的详细视图.
第二个问题涉及向DirectionsViewController添加一个导航栏,但现在就让它离开.
以下是一些您可能会发现有用的方法:
//inside DirectionsViewController
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)
{
DetailedDirectionsViewController *vc = [[DetailedDirectionsViewController alloc] initWithStyle:UITableViewStyleGrouped];
vc.instruction = [turnList objectAtIndexPath:indexPath.row];
[self.tabBarController presentModalViewController:vc animated:YES];
}
//inside DetailedDirectionsViewController
- (UITableViewCell *) tableView:(UITableView *) cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"directionsCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
[[NSBundle mainBundle] initWIthNibNamed:@"DetailedDirectionsViewCell" owner:nil options:nil];
cell = self.tableViewCell;
self.tableViewCell = nil;
}
//here I configure the custom cell
return cell;
}
Run Code Online (Sandbox Code Playgroud)
我不认为其他方法是有意义的,因为它们要么按预期工作,要么几乎是默认方法.
总结一下:
DirectionsViewController - 基本上是一个UITableViewController自定义单元格.No .xib文件DetailedDirectionsViewController - 有关DirectionsViewController条目的详细信息.这里的单元格应该来自.XIB文件,但是它已经坏了.DetailedDirectionsViewCell - 这是自定义单元格.我无法设置其文件所有者.
roh*_*tel 11
好的..您没有IBOutlet从文件所有者创建连接.看一下截图.您可以IBOutlet从CustomCell的视图(使用红色箭头)创建.
照顾您的代码,请按照以下步骤操作.
1)转到CustomCell.h文件.正如你所说customCell.xib有两个UILabel(假设label1 & label2)你必须声明属性并在CustomCell.h文件和.m文件中创建出口合成并释放它.请参阅我的此代码屏幕.

2)现在CustomCell.xib,选择CustomCell不是文件所有者的视图(文件所有者应该NSObject只继承)转到Identity Inspector(用红色椭圆标记)并选择相应的Customcell类(用红色矩形标记).
3)右键单击customcell的视图并连接标签.并保存..

4)DirectionsViewController.m你有这个UITableView的委托方法cellForRowAtIndexPath.像这样改变它:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CustomCellIdentifier = @"CustomCell";
EditProjectCustomCell *cell = (EditProjectCustomCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier]; // typecast to customcell
[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"EditProjectCustomCell" owner:self options:nil];
for (id oneObject in nib)
if ([oneObject isKindOfClass:[EditProjectCustomCell class]])
cell = (EditProjectCustomCell *)oneObject;
[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
}
cell.label1.text=[someArray1 ObjectAtIndexPath: indexPath.row];
cell.label2.text=[someArray2 ObjectAtIndexPath: indexPath.row];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
在numberOfRowsInSectionDataSource方法中返回值时,将调用此委托方法的次数.每次cell.label为空,您将通过调用此行将数据添加到标签.因此,无需像每次在第79-90行之间那样创建标签.http://pastebin.com/Vd4PKjTu
cell.label1.text=[someArray ObjectAtIndexPath: indexPath.row];
Run Code Online (Sandbox Code Playgroud)
创建自定义单元格意味着您自己创建UI(即.xib),接口和实现(.h,.m文件),UITableViewCell并在您的类(即DirectionsViewController.m) cellForRowAtIndexPath委托方法中采用它们.
| 归档时间: |
|
| 查看次数: |
10852 次 |
| 最近记录: |