0

我正在尝试向表格单元格添加动态水平滚动。

我在搜索了一段时间后找到了一个示例,但由于示例项目只是一个视图,它直接连接到包含大部分相关代码的应用程序委托。大部分在applicationDidFinishLaunching.

你们中有人知道我应该如何将此代码添加到我的项目中吗?

在此先感谢,汤姆

编辑:这是我下载的示例项目的链接:http: //blog.sallarp.com/wp-content/uploads/2008/11/slidemenu.zip

这是它应该如何工作的 youtube 剪辑:http ://www.youtube.com/watch?v=wFqBNXZ4SHI

编辑 2(新代码):

"famorables" 用 5 个单字串声明

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

//Create Cell
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];    
}
//Create a UIScroll View
UIScrollView    *scrollview  = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 80)]; 
scrollview.contentSize = CGSizeMake(self.view.frame.size.width * 2, 80); 
scrollview.showsHorizontalScrollIndicator = NO;

float totalButtonWidth = 0.0f;
famorableArray = self.famorables;


for(int i = 0; i < [self.famorables count]; i++){

    UIButton *famorableButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [famorableButton setFrame:CGRectMake(0.0f, 0.0f, 100.0f, 30.0f)];
    [famorableButton setTitle:[NSString stringWithFormat:@"%@", [famorableArray objectAtIndex:[indexPath row]]] forState:UIControlStateNormal];

    // Move the buttons position in the x-demension (horizontal).
    CGRect btnRect = famorableButton.frame;
    btnRect.origin.x = totalButtonWidth;
    [famorableButton setFrame:btnRect];

    // Add the button to the scrollview
    [scrollview addSubview:famorableButton];

    // Add the width of the button to the total width.
    totalButtonWidth += famorableButton.frame.size.width;

}

[cell.contentView addSubview:scrollview];
return cell;
}
4

1 回答 1

1

好的试试这个

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

        //Create Cell
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];    
        }
     //Create a UIScroll View
     UIScrollView    scrollview  = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, (it will be the height of the Cell u want))]; 
    scrollview.contentSize = CGSizeMake(self.view.frame.size.width * 2,(it will be the height of the Cell u want)); 
    scrollview.showsHorizontalScrollIndicator = NO;

/*
Now add every this u might want to add in ur Scroll view.

keep that in mind that the height and width of contentSize and ScrollView will be depandent on ur requirement

Make sure u add every thing u want in the Scroll view will be the part of Scroll View
like for label

//Add Something to Scroll View
[scrollView addSubview:label];
*/

//Add Scroll view to Cell

[cell.contentView addSubview:scrollView];
return cell;
}

这将起作用

如有任何疑问,请随时询问

于 2012-07-20T10:49:24.023 回答