Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 使用包含UItextview的自定义单元格滚动UITableView时出现问题_Iphone_Objective C_Uitableview_Uitextview - Fatal编程技术网

Iphone 使用包含UItextview的自定义单元格滚动UITableView时出现问题

Iphone 使用包含UItextview的自定义单元格滚动UITableView时出现问题,iphone,objective-c,uitableview,uitextview,Iphone,Objective C,Uitableview,Uitextview,我有一个带有自定义单元格的表视图,其中包含UITextView、UILabel和UIButton 问题是, 第一次加载表格时,将显示2个单元格,这些单元格都很好。但当滚动表格时,任何一个单元格都会从屏幕上滚出来,应用程序会突然终止,而不会向控制台显示任何异常错误 这是我的密码 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSLog

我有一个带有自定义单元格的表视图,其中包含UITextView、UILabel和UIButton

问题是,

第一次加载表格时,将显示2个单元格,这些单元格都很好。但当滚动表格时,任何一个单元格都会从屏幕上滚出来,应用程序会突然终止,而不会向控制台显示任何异常错误

这是我的密码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

NSLog(@"In tableView:Cell");    
static NSString *CustomCellIdentifier = @"CustomCellIdentifier ";

CourtsFavoriteCustomCell* cell = (CourtsFavoriteCustomCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];

if( cell == nil)
    {
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CourtsFavoriteCustomCell"
                                                    owner:self options:nil];

    for (id oneObject in nib) 
        if ([oneObject isKindOfClass:[CourtsFavoriteCustomCell class]])
        cell = (CourtsFavoriteCustomCell *)oneObject;

//*********** Creating button inside each TableView cell..

        UIButton *mapButton = [UIButton buttonWithType:UIButtonTypeRoundedRect] ;

        [mapButton setFrame:CGRectMake(120.0f, 157.0f, 72.0f, 32.0f)] ;
        //btnDetail.backgroundColor = [UIColor grayColor];
        [mapButton setTitle:@"Map" forState:UIControlStateNormal];
        [mapButton setTitleColor: [UIColor redColor] forState: UIControlStateNormal];
        //[mapButton.titleLabel setFont:[UIFont fontWithName:@"Verdana-Bold" size:12]];
        [mapButton setBackgroundColor:[UIColor clearColor]];
        [mapButton sizeThatFits:mapButton.frame.size];
        [cell addSubview:mapButton];
        [mapButton addTarget:self 
                      action:@selector(cellMapButtontapped:)
            forControlEvents:UIControlEventTouchUpInside];
        forState:UIControlStateNormal];

    }
NSLog(@"App get terminated after showing this log message to console when scrolling tableview");



    cell.name.text         = favCourtName;  // name is a UIText view and if comment this line of code, every thing works fine
    cell.address.text      = favCourtAddress;   


    cell.accessoryType          = UITableViewCellAccessoryDetailDisclosureButton; 

     return cell;


}
我正在自定义单元格中使用UITextView(代码中的Cell.name)。当我尝试注释UITextView代码时,一切正常。


请帮助我:)thanx..

favCourtName在某处发布,是否只分配一次?或者在每个单元格上初始化它

cell.Name.text         = favCourtName;
关于性能的第二件事,如果您使用下面的代码,当它从Nib文件加载时,它将在滚动时变慢,相反,您可以使用
initWithStyle:

NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CourtsFavoriteCustomCell"
                                                owner:self options:nil];

for (id oneObject in nib) 
    if ([oneObject isKindOfClass:[CourtsFavoriteCustomCell class]])
    cell = (CourtsFavoriteCustomCell *)oneObject;
来自苹果文档

重要提示:不应在UIScrollView对象中嵌入UIWebView或UITableView对象。如果这样做,可能会导致意外行为,因为两个对象的触摸事件可能会混淆并错误处理

UITableView和UITextView都是UIScrollView的子类

一旦你的记忆问题得到解决,你仍然会得到意想不到的行为。您可能应该重新考虑这个设计,选择一个受支持的设计

您没有提供足够的信息来进一步提供帮助。控制台上显示了什么错误消息


与您的问题无关:使用大写字母开头字符(即
cell.name
)命名属性是不典型的。单元格上的Name属性应为小写(即,
Name
)。

@All,所有答案均为Thanx.) 我解决了这个问题。它不支持UITextView

我之所以在这里写作是因为,如果有人带着同样的问题来到这里,这可能会有所帮助

这个问题其实很简单,但我花了2天时间才发现,因为它并没有显示任何异常

我所做的只是在我的ViewDidLoad方法中的“favCourtName”中添加了“retain”。就是这样,

NSString * favCourtName = [[[NSString alloc] initWithFormat:@"myCourt"] retain];

“保留”这个词很神奇。谢谢

什么是favCourtName?是否已正确设置?我是否可以知道uitextview对象在何处声明了相同的类或某些位置。属性很重要,因此如果要将更改指定给retain@deepak,favCourtName是一个NSString,是的,它已正确设置。@maheswaran,UItextView在自定义单元格中声明@属性(非原子,保留)UITextView*名称;我的猜测-名称是在nib文件中设置的出口。样式名称已(或应)在nib文件中设置。@Jignesh Brahmkhatri,favCourtName是一个NSString。cell.name中的名称是自定义单元格类中的UITextView。它的属性类似于@property(非原子,retain)UITextView*名称;为什么从nib加载Iam是因为它是定制设计。我可以用什么样的方法使它快速-实际上我在代码中使用了cell.name。我在这里打字时犯了一个打字错误(现已编辑)。如果在UITableView单元格中使用UITextView是不明智的,那么我还可以使用什么来显示长字符串-感谢使用UILabel并删除字符串“详细信息”在详细信息视图控制器中,通过将详细信息视图控制器推送到根视图控制器所在的导航控制器上,可以获得该控制器?从这个简短的交流中,我无法告诉您应该如何设计应用程序的用户体验。但你上面所说的行不通。非常感谢你的回答:)