ページ 1 / 1
【Objective-c iPhone】UITableViewControllerの上にスクロールをしない画像を置きたい
Posted: 2010年12月09日(木) 10:54
by TEAS TEA
UITableViewControllerでアプリケーションを作っております。
この上にバナーのような画像を乗せてみたのですがUITableViewControllerと共にスクロールしてしまいます。
これを改善する方法はないのでしょうか?
コード:
- (void)viewDidLoad {
[super viewDidLoad];
UIImageView *backGroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:nil]];
backGroundView.userInteractionEnabled = YES;
// バナー画像 ボタンの背景を画像にしています。
UIButton *twitterButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 360, 320, 60)];
[twitterButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[twitterButton setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
// [twitterButton setTitle:@">>Twitterでつぶやく" forState:UIControlStateNormal];
twitterButton.titleLabel.font = [UIFont systemFontOfSize:14.0];
[twitterButton setBackgroundImage:[UIImage imageNamed:@"banner.png"] forState:UIControlStateNormal];
// [twitterButton addTarget:self action:@selector(twitterEvent:) forControlEvents:UIControlEventTouchUpInside];
[backGroundView addSubview:twitterButton];
[twitterButton release];
[self.view addSubview:backGroundView];
[backGroundView release];
略
Re: 【Objective-c iPhone】UITableViewControllerの上にスクロールをしない画像を
Posted: 2010年12月09日(木) 14:38
by TEAS TEA
やりかたがなんとなくわかりました。
tableViewの上に新規にViewを作ってそこに配置してるつもりだったのですが違うみたい?ですね・・・
色々調べてみるとAppDelegateのWindowにセットすれば出来そうと思い変更した所、近い動作までいきました。
コメントアウトしてあるのがバナーです。
しかしまた問題が3点発生してしまいました。
1点目
tabBarControllerを追加するとテーブルビューがスクロールしない
2点目
なぞのナビゲーションバーがある
(tabBarControllerを追加するとその上にナビゲーションバーの様なのができてしまう)
3点目
バナーをタッチできない
又、バナーを表示してしまうとタブが表示できなくなってしまう。
質問ばかりですみません・・・
なんとか解決したく色々と調べて入るのですが解決できそうにありません。
コード:
#import "MyTableViewCellAppDelegate.h"
#import "RootViewController.h"
@implementation MyTableViewCellAppDelegate
@synthesize window;
@synthesize navigationController;
@synthesize tabBarController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
UITabBarController *tab1Controller = [[[UITabBarController alloc] initWithNibName:@"tab1" bundle:nil] autorelease];
UITabBarController *tab2Controller = [[[UITabBarController alloc] initWithNibName:@"tab2" bundle:nil] autorelease];
UITabBarController *tab3Controller = [[[UITabBarController alloc] initWithNibName:@"tab3" bundle:nil] autorelease];
UITabBarController *tab4Controller = [[[UITabBarController alloc] initWithNibName:@"tab4" bundle:nil] autorelease];
tabBarController.viewControllers = [NSArray arrayWithObjects:tab1Controller, tab2Controller, tab3Controller, tab4Controller, nil];
tab1Controller.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"タブ1" image:[UIImage imageNamed:@"hoge1.png"] tag:0];
tab2Controller.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"タブ2" image:[UIImage imageNamed:@"hoge2.png"] tag:1];
tab3Controller.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"タブ3" image:[UIImage imageNamed:@"hoge3.png"] tag:2];
tab4Controller.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"タブ4" image:[UIImage imageNamed:@"hoge4.png"] tag:3];
// バナー
/*
UIImageView *backGroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:nil]];
backGroundView.userInteractionEnabled = YES;
UIButton *twitterButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 420, 320, 60)];
[twitterButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[twitterButton setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
twitterButton.titleLabel.font = [UIFont systemFontOfSize:14.0];
[twitterButton setBackgroundImage:[UIImage imageNamed:@"banner.png"] forState:UIControlStateNormal];
[backGroundView addSubview:twitterButton];
[twitterButton release];
*/
[window addSubview:navigationController.view];
// [window addSubview:tabBarController.view];
// [window addSubview:backGroundView];
// [backGroundView release];
[window makeKeyAndVisible];
return YES;
}
Re: 【Objective-c iPhone】UITableViewControllerの上にスクロールをしない画像を
Posted: 2010年12月09日(木) 15:15
by TEAS TEA
何度も修正したものをあげてすみません><
本当に申し訳ないです。
何とか解決したく試行錯誤を繰り返しているのですがイマイチうまくいきません。
先ほどの不具合を改善する為に自分なりに無理矢理作ったソースが下記になります。
デフォルトのビューの範囲を無理矢理変えております。
RootViewController.h と DataViewController.h の2つのページを作ってみたのですがタブを押しても画面遷移してくれません。
何とかここまで修正出来れば開発の流れがわかるのですが・・・。
アドバイスを頂けないでしょうか。
もしくはこれだけでは不十分でしたらプロジェクトを添付させて頂きます。
1点目
tabBarControllerを追加するとテーブルビューがスクロールしない
→ナビゲーションバーとバナーのビューの範囲を変えたので出来る様にはなったのですがこれが正しいやり方なのでしょうか?
2点目
なぞのナビゲーションバーがある
→無理矢理範囲を狭めて見えなく?したのですが多分まずい気もします・・・。
3点目
バナーをタッチできない
→修正してみたのですがこんなやり方でいいのでしょうか?
コード:
#import "MyTableViewCellAppDelegate.h"
#import "RootViewController.h"
#import "DataViewController.h"
@implementation MyTableViewCellAppDelegate
@synthesize window;
@synthesize navigationController;
@synthesize tabBarController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// ナビゲーションカラーの変更
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
// タブの作成
self.tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
UITabBarController *tab1Controller = [[[UITabBarController alloc] initWithNibName:@"RootViewController" bundle:nil] autorelease];
UITabBarController *tab2Controller = [[[UITabBarController alloc] initWithNibName:@"DataViewController" bundle:nil] autorelease];
UITabBarController *tab3Controller = [[[UITabBarController alloc] initWithNibName:@"tab3" bundle:nil] autorelease];
UITabBarController *tab4Controller = [[[UITabBarController alloc] initWithNibName:@"tab4" bundle:nil] autorelease];
tabBarController.viewControllers = [NSArray arrayWithObjects:tab1Controller, tab2Controller, tab3Controller, tab4Controller, nil];
tab1Controller.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"調合表" image:[UIImage imageNamed:@"hoge1.png"] tag:0];
tab2Controller.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"キークエ" image:[UIImage imageNamed:@"hoge2.png"] tag:1];
tab3Controller.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"タブ3" image:[UIImage imageNamed:@"hoge3.png"] tag:2];
tab4Controller.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"タブ4" image:[UIImage imageNamed:@"hoge4.png"] tag:3];
tabBarController.view.frame = CGRectMake(0,375,320,45);
// バナーの作成
UIView *backGroundView = [[UIView alloc] init];
backGroundView.frame = CGRectMake(0,420,320,60);
backGroundView.userInteractionEnabled = YES;
UIButton *twitterButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
[twitterButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[twitterButton setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
twitterButton.titleLabel.font = [UIFont systemFontOfSize:14.0];
[twitterButton setBackgroundImage:[UIImage imageNamed:@"banner.png"] forState:UIControlStateNormal];
[backGroundView addSubview:twitterButton];
[twitterButton release];
[window addSubview:navigationController.view];
[window addSubview:tabBarController.view];
[window addSubview:backGroundView];
[window makeKeyAndVisible];
[backGroundView release];
return YES;
}
Re: 【Objective-c iPhone】UITableViewControllerの上にスクロールをしない画像を
Posted: 2010年12月09日(木) 21:45
by TEAS TEA
なんとか修正し立て見たのですが上手くタブが動作してくれません・・・。
ゲーム以外の質問で申し訳ございません><
Re: 【Objective-c iPhone】UITableViewControllerの上にスクロールをしない画像を
Posted: 2010年12月10日(金) 08:19
by TEAS TEA
わかりにくいと思いましたのでプロジェクトを添付させて頂きました。
IBを使わないで作成しております。
一番左のタブを押したらRootViewController
左からに番目ならDataViewControllerといった感じにしたいのですが上手くいきません・・・
お詳しい方がおりましたらお手数おかけいたしますがどうかソースを見ては頂けないでしょうか
URL:
http://www1.axfc.net/uploader/He/so/304595.zip
PASS:c
Re: 【Objective-c iPhone】UITableViewControllerの上にスクロールをしない画像を
Posted: 2010年12月11日(土) 03:47
by Justy
ざっくりとしか見ていませんが、あちこちおかしいです。
主に didFinishLaunchingWithOptionsで
・ 4つの UITabBarControllerの生成。
RootViewController.xibから作るなら、UITabBarControllerじゃないでしょう。
加えて DataViewController.nibや tab3.xibなどが無いのに生成しようとしています。
・ UITabBarController.viewの大きさがおかしい
このビューはタブバーだけではなく、リストなどが表示される領域も含んでいたはずです。
これを小さくしすぎたら、何も表示されないでしょう。
タブバーだけを変えるならtabBarController.tabBarの方を変更するべきです。
・ 構成がおかしい
IB側から RootViewControllerが起動するようになっています。
なので、タブからの表示はされないにも関わらず表示されているかと思われます。
他にもありそうですが、とりあえずはここまで。
ところで質問される度に名前を変えているのですか?
Re: 【Objective-c iPhone】UITableViewControllerの上にスクロールをしない画像を
Posted: 2010年12月12日(日) 18:46
by TEAS TEA
連絡が遅くなってしまいすみません><
これからはTEAS TEAで固定にします。
ご迷惑をおかけしました。
今まで本などをあまり見ずに開発をしてきたのですがこの機会にUIkit詳細リファレンスという本を購入しました。
主にIBを使わないで開発している本です。
それをみながら全く別のソース?を作ってみました。
しかしまだ問題点が御座います。
1点目
表示されているTabの場所を変えたい
通常、タブは一番下に表示されると思うのですがこれをバナー(60px)の上にしたいです。
2点目
テーブルビューの表示範囲を変えたい。
※バナーが一番上にくるので下の行が隠れてしまうので・・・
┌────┐
│ │
│テーブル│
│ │
┝─ ──┤ ←ここまでをテーブルの範囲にしたい
│ tab │
┝───┤
│バナー │
└────┘
またこの質問は別の掲示板でも質問させて頂いております。
マルチポストは禁止されているかもしれませんがどうしても解決したいんです。
コード:
-----------------------KeyView-----------------------
#import "KeyViewController.h"
@implementation KeyViewController
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 25;
}
// initialize
- (id)init {
if ( (self = [super init]) ) {
// self.tableView.frame = CGRectMake( 0, 0, 320, 200 );
// self.frame = CGRectMake( 0, 0, 320, 200 );
// tabBar用設定
self.title = @"キー";
UIImage* icon = [UIImage imageNamed:@"key.png"];
self.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"キー" image:icon tag:0] autorelease];
//self.view.frame = CGRectMake( 0, 0, 320, 200 );
}
return self;
}
-----------------------AppDelegate-----------------------
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CGRect frameForWindow = [[UIScreen mainScreen] bounds];
window = [[UIWindow alloc] initWithFrame:frameForWindow];
// 基点となるControllerを作成
rootController = [[UITabBarController alloc] init];
// ViewController1とViewController2を作成する
ViewController1* tab1 = [[[ViewController1 alloc] init] autorelease];
KeyViewController* tab3 = [[[KeyViewController alloc] init] autorelease];
CompoundViewController* tab4 = [[[CompoundViewController alloc] init] autorelease];
// tab3.view.frame = CGRectMake( 0, 50, 320, 200 );
// 作ったViewControllerをControllerにまとめて追加
NSArray* controllers = [NSArray arrayWithObjects:tab3, tab1, tab4, nil];
[(UITabBarController*)rootController setViewControllers:controllers animated:NO];
// rootController.view.frame = CGRectMake(0,375,320,45);
// windowにControllerのviewを追加
[window addSubview:rootController.view];
// バナーの作成
UIView *banner = [[UIView alloc] init];
banner.frame = CGRectMake(0,372,320,60);
banner.userInteractionEnabled = YES;
UIButton *twitterButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
[twitterButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[twitterButton setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
twitterButton.titleLabel.font = [UIFont systemFontOfSize:14.0];
[twitterButton setBackgroundImage:[UIImage imageNamed:@"banner.png"] forState:UIControlStateNormal];
[banner addSubview:twitterButton];
[twitterButton release];
[window addSubview:banner];
[banner release];あ
[window makeKeyAndVisible];
return YES;
}
Re: 【Objective-c iPhone】UITableViewControllerの上にスクロールをしない画像を
Posted: 2010年12月12日(日) 23:52
by Justy
規約上マルチポストは禁止ではありませんが、相互リンクを張りましょう。
[tabs][tabs: ]
http://dixq.net/board/board.html[/tabs]
マルチポスト先は
こちらですね。
[hr]
さて、コードが新しくなって動かしていないので、詳細までつめてはいませんが、まず
justy さんが書きました: UITabBarController.viewの大きさがおかしい
このビューはタブバーだけではなく、リストなどが表示される領域も含んでいたはずです。
これを小さくしすぎたら、何も表示されないでしょう。
タブバーだけを変えるならtabBarController.tabBarの方を変更するべきです。
と書いたのですが、全く反映されていないようです。
tabBarの位置を変更すれば概ね出来るか、方向性が見えてくるのではないかと思いますよ。
Re: 【Objective-c iPhone】UITableViewControllerの上にスクロールをしない画像を
Posted: 2010年12月13日(月) 01:49
by TEAS TEA
色々とありがとうございます。
>>UITabBarController.viewの大きさがおかしい
すみません・・・本を見ながら新しくプロジェクトを作って試してみて全く違うソースになってしまいました。
このソースだと何処を修正すればよいのでしょうか・・・?本当に無知ですみません。
本を読みながら色々と調べてはいるのですが解決できません><
http://www1.axfc.net/uploader/Sc/so/183019.zip
PASS:1
Re: 【Objective-c iPhone】UITableViewControllerの上にスクロールをしない画像を
Posted: 2010年12月13日(月) 02:16
by Justy
なるほど、このコードなら 36行目のコメントを解除して
コード:
rootController.view.frame = CGRectMake(0,0,320,420);
に。続いて47行目を
コード:
banner.frame = CGRectMake(0,420,320,60);
とすればとりあえずは近い形になるのではないでしょうか。
Re: 【Objective-c iPhone】UITableViewControllerの上にスクロールをしない画像を
Posted: 2010年12月13日(月) 04:22
by TEAS TEA
Justy様
出来ました!!!!!
本当にありがとうございます。非常に助かりました><
何とお礼をいっていいやら・・・。
遅くまでありがとうございました。