1

すべてのセルに入れ子になった UIview を含むテーブル ビューを表示したいのですが、いくつかの問題に直面しています。

1) テーブル ビューをスクロールしようとすると、アプリがクラッシュします。

アプリデリゲートにサブビューの代わりにルートビューを追加することで解決

さて問題その2

2)テーブルセル内に水平スクロールビューを追加したいので、単一のセルに3つのサブビューを表示でき、セル内で水平にスクロールできます..どうすればそれを行うことができますか. 私はこれをしたい..

ここに画像の説明を入力

これを達成するために、私はこれをコードしています..

 - (id)initWithFrame:(CGRect)frame
  {
self = [super initWithFrame:frame];
if (self) {
    UIView *wagon = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 430, 187)];
    UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"wagon.png"]];
    wagon.backgroundColor = background;

    UIScrollView *scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 830, 187)];
    scrollview.showsVerticalScrollIndicator=YES;
    scrollview.scrollEnabled=YES;
    scrollview.userInteractionEnabled=YES;

   UIView *videoview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 220 , 100)];

    UIImageView *video = [[UIImageView alloc]initWithFrame:CGRectMake(wagon.frame.origin.x+18, wagon.frame.origin.y+35, 220, 100)];
    UIImage *bgImage = [UIImage imageNamed:@"video.png"];
    video.image = bgImage;
    videoview.contentMode = UIViewContentModeLeft;
    [videoview addSubview:video];

    UIView *textview = [[UIView alloc]initWithFrame:CGRectMake(wagon.frame.origin.x+238,wagon.frame.origin.y+28, 150 , 187)];
    textview.contentMode = UIViewContentModeRight;
    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(28,10, 150 , 87)];
    label.text=@"This is testing text for IOS app to check line are aligned or not and to check video image and nested views for UIviews";
    label.backgroundColor = [UIColor clearColor];
    label.textColor=[UIColor redColor];
    label.numberOfLines = 4;
    [textview addSubview:label];

    [wagon addSubview:textview];
    [wagon addSubview:videoview];
    [scrollview addSubview:wagon];
    [self addSubview:scrollview];       
  }
   return self;
   }

テーブルセルからこのビューを呼び出します

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = @"StateCell";
UITableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Wagon1 *wg=[[Wagon1 alloc]init];
[cell addSubview:wg];
return cell;

}

wg を追加することで、ワゴン ビューの 1 台のトレイン ボギーが得られます。最終的にまたは最初に 2 台のワゴン ビューとエンジンが必要です。

** テーブル クラッシュの問題が解決しました**

1)クラッシュの問題を解決するために、私はstackoverflowを検索し、デリゲートに追加するか、保持または強力なbla bla ..に変更するなどの解決策を見つけましたが、これらのどれも私にとってはうまくいきません。これが私のコードです。もう1つ、XIB、ペン先、またはストーリーボードを使用していません..

@interface MainScreenViewController : UIViewController 
{
UITableView* table;
 NSString * name;
 }
 @property (strong, retain) UITableView *table;
 @property (strong, retain) NSString *name;;
 @end

.m ファイル

@interface MainScreenViewController ()
@end
@implementation MainScreenViewController
@synthesize table;
@synthesize name;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil  
{
self = [super initWithNibName:Nil bundle:Nil];
if (self) {
    // Custom initialization
}
return self;
 }
- (void)viewDidLoad
 {
[super viewDidLoad];
name=[[NSString alloc]init];
name=@"testing of row";
CGRect frame = self.view.frame;
table= [[UITableView alloc] initWithFrame:frame];
table.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
[table setDelegate:self];// app crash here 
 table.dataSource = self;// here also 
[table reloadData];
   [self.view addSubview:table];
 }
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
  return 8;
 }
 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  {
  return @"test";
  }

 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath: (NSIndexPath*)indexPath;
   {
  return 190;
  }
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
 {
// Return the number of sections.
return 1;
  }
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
   static NSString *simpleTableIdentifier = @"SimpleTableItem";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

  if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = name;
return cell;
  }
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
  return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
  }
 - (void)didReceiveMemoryWarning
  {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
   }
 @end
4

3 に答える 3

1

私はあなたのコードを試してみましたが、私にとっては完璧に機能しています。問題はView Controllerの初期化にあるはずです。これを試してください

于 2013-04-23T11:09:13.583 に答える