IOS,UITabelView不滚动

时间:2014-09-08 20:00:51

标签: ios objective-c

我有一个UITableView添加到UIView,当数据从数据库返回时我将数据传递给NSMutableArray。当单元格被渲染时,我在单元格内创建UIViews,并将数据输出到此UIView中。现在使用UIViews渲染单元格,我可以看到UIViews正在显示。但滚动条不起作用,因为我无法向下滚动以查看包含带有数据的UIViews的其他单元格。

代码:

        tableViewThreads = [[UITableView alloc] initWithFrame:CGRectMake(0, 104, screenRect.size.width, 336)];
        tableViewThreads.delegate = self;
        tableViewThreads.dataSource = self;
        tableViewThreads.bounces = YES;
        tableViewThreads.separatorStyle = UITableViewCellSeparatorStyleNone;
        [viewTopThread addSubview:tableViewThreads];

        tableViewThreads.userInteractionEnabled = YES;
        [self.view bringSubviewToFront:tableViewThreads];



        -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
            if(tableViewThreads == tableView){
            return [threadsArray count];
            }

            return 0;
        }

        -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
            static NSString *cellIdentifier = @"cell";

            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

            if (cell == nil)
            {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
            }
            if(tableViewThreads == tableView){
            ThreadInfo *threadInfo = (ThreadInfo*)[self.threadsArray objectAtIndex:indexPath.row];

            [cell.contentView addSubview:[self setupThreadItem:threadInfo]];

            //[cell.textLabel setText:tweet];
            //[cell.detailTextLabel setText:@"via Codigator"];
            }

            return cell;
        }

        - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
        {
            if(tableViewThreads == tableView){

            return 122;

            }

            return 0;
        }


-(void)renderThreadInfo:(NSDictionary*)dic{

                NSDictionary *thread = [dic objectForKey:@"thread"];

                int t_ID;
                int t_U_ID;
                int t_C_ID;
                NSString *t_Name;
                NSString *t_Description;
                NSDate *t_Created;
                int t_Flagged;
                int t_Rated;

                for(NSDictionary *dict in thread)
                {
                if((NSNull *)[dict objectForKey:@"T_ID"] != [NSNull null]){
                    t_ID = [[dict objectForKey:@"T_ID"] intValue];
                }
                if((NSNull *)[dict objectForKey:@"T_U_ID"] != [NSNull null]){
                    t_U_ID = [[dict objectForKey:@"T_U_ID"] intValue];
                }
                if((NSNull *)[dict objectForKey:@"T_C_ID"] != [NSNull null]){
                    t_C_ID = [[dict objectForKey:@"T_C_ID"] intValue];
                }
                if((NSNull *)[dict objectForKey:@"T_Name"] != [NSNull null]){
                    t_Name = [dict objectForKey:@"T_Name"];
                }
                if((NSNull *)[dict objectForKey:@"T_Description"] != [NSNull null]){
                    t_Description = [dict objectForKey:@"T_Description"];
                }
                if((NSNull *)[dict objectForKey:@"T_Created"] != [NSNull null]){
                    NSString *timestampString = [dict objectForKey:@"T_Created"];
                    double timestampDate = [timestampString doubleValue];
                    t_Created = [NSDate dateWithTimeIntervalSince1970:timestampDate];
                }
                if((NSNull *)[dict objectForKey:@"T_Flagged"] != [NSNull null]){
                    t_Flagged = [[dict objectForKey:@"T_Flagged"] intValue];
                }
                if((NSNull *)[dict objectForKey:@"T_Rated"] != [NSNull null]){
                    t_Rated = [[dict objectForKey:@"T_Rated"] intValue];
                }

                ThreadInfo *threadObj = [ThreadInfo new];
                threadObj.iD = t_ID;
                threadObj.userId  = t_U_ID;
                threadObj.catId = t_C_ID;
                threadObj.name = t_Name;
                threadObj.description = t_Description;
                threadObj.timeStampCreated = t_Created;
                threadObj.flagged = t_Flagged;
                threadObj.rated = t_Rated;

                [threadsArray addObject:threadObj];

                [tableViewThreads reloadData];

                }

            }

1 个答案:

答案 0 :(得分:0)

我正在将UITableView添加到错误的UIView。

应该是:

[self.viewCreateThread addSubview:tableViewThreads];

但是当我现在滚动应用程序崩溃时,我将打开另一个问题。

由于