I hope you can help me to set the background color of my navigation bar. As you can see on the first picture below, the bar is light blue/gray, but i want it to be like the second picture "Favoritter".
I have another viewController in my project (see the second picture "Favoritter") where it works. But I can not see what I'm doing wrong here and the navigationBar will only take this light blue/gray color and not yellow.
My code is like this:
------------------InstantCabAppDelegate.m file-----------START-------
//InstantCabAppDelegate.m file
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Create tabBarController instance
tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
// Create instances of navigation controller and view controllers
orderController = [[OrderController2 alloc] initWithNibName:#"Order2" bundle:nil];
UINavigationController* firstnavigationController = [[UINavigationController alloc] initWithRootViewController:orderController];
ICStatusViewController *statusController = [[ICStatusViewController alloc] initWithStatus];
UINavigationController *statusNavController = [[UINavigationController alloc] initWithRootViewController:statusController];
ICSettingsViewController *settingsController = [[ICSettingsViewController alloc] init];
UINavigationController *settingsNavController = [[UINavigationController alloc] initWithRootViewController:settingsController];
UIViewController *company_controller = nil;
company_controller = [[ICCompaniesGridController alloc] initWithCompanies:[[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Companies" ofType:#"plist"]]];
tabBarController.viewControllers = [NSArray arrayWithObjects:firstnavigationController, settingsNavController, statusNavController, company_controller, nil];
[window setRootViewController:tabBarController];
[window makeKeyAndVisible];
return YES;
}
------------------ICStatusViewController.m file-----------START-------
// ICStatusViewController.m file
#import "ICStatusViewController.h"
#import "LocalizationSystem.h"
#import "ICTemporaryStore.h"
#import "Debug.h"
#implementation ICStatusViewController
#synthesize doneCallbackBlock=_doneCallbackBlock, cancelCallbackBlock=_cancelCallbackBlock;
#synthesize myTableView, no_statuses, no_statuses_label, delegate;
- (id)initWithStatus
{
if ((self = [super initWithNibName:#"StatusList" bundle:nil]))
{
self.title = AMLocalizedString(#"kStatusTitle", #"");
self.tabBarItem.image = [UIImage imageNamed:#"status_icon"];
self.no_statuses = AMLocalizedString(#"kStatusListNoStatusList", #"");
first_color = TABLE_VIEW_BACKGROUND_COLOR;
second_color = first_color;
self.doneCallbackBlock = nil;
self.cancelCallbackBlock = nil;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"background-nologo"]];
self.view.backgroundColor = [UIColor clearColor];
self.myTableView.backgroundColor = TABLE_VIEW_BACKGROUND_COLOR;
if ([statusObjects count] == 0)
{
self.myTableView.hidden = YES;
self.no_statuses_label.text = self.no_statuses;
self.no_statuses_label.hidden = NO;
no_status_background.hidden = NO;
}
[self.no_statuses_label setTextColor:[UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0]];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if ([statusObjects count] == 0)
{
self.myTableView.hidden = YES;
self.no_statuses_label.text = self.no_statuses;
self.no_statuses_label.hidden = NO;
no_status_background.hidden = NO;
self.navigationItem.rightBarButtonItem = nil;
}
else
{
self.myTableView.hidden = NO;
self.no_statuses_label.hidden = YES;
no_status_background.hidden = YES;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSInteger retval = 0;
for (int i=0; i<[statusObjects count]; i++)
{
StatusObj *add = [statusObjects getStatusAtIndex:i];
if (add.status_id && [add.status_id length] > 0 && [add.status_type isEqualToString:#"STATUS_ORDER"])
{
retval++;
}
}
return retval;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifierStatus = #"StatusCell";
__unsafe_unretained NSString *CellIdentifier = CellIdentifierStatus;
StatusCell* cell = (StatusCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[StatusCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
[[cell textLabel] setTextColor:TABLE_VIEW_TEXT_LABEL_COLOR];
[[cell detailTextLabel] setTextColor:TABLE_VIEW_DETAIL_TEXT_LABEL_COLOR];
[[cell detailTextLabel] setNumberOfLines:3];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
dateString = [dateFormat stringFromDate:current_order.order.time];
NSString *str = AMLocalizedString(#"kStatusListDetailsToDay", #"");
textLabelString = [NSString stringWithFormat:#"%# - %#", str, dateString];
[cell.textLabel setText:textLabelString];
[cell.detailTextLabel setText:detailTextString];
[cell setBackgroundColor:[UIColor redColor]];
[cell.dateLabel setBackgroundColor:[UIColor clearColor]];
cell.accessoryType = UITableViewCellAccessoryNone;
return cell;
}
------------------ICStatusViewController.h file-----------START-------
// ICStatusViewController.h
#import <UIKit/UIKit.h>
#import "Status.h"
#import "StatusCell.h"
#import "StatusControllerDelegate.h"
#import "ICStatusDetailsController.h"
typedef void (^ICStatusViewControllerDoneCallbackBlock)(id userInfo);
typedef void (^ICStatusViewControllerCancelCallbackBlock)(void);
#interface ICStatusViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UIActionSheetDelegate, ICStatusDetailsControllerDelegate> {
id<Statuses> statusObjects;
NSString *no_statuses;
NSOperationQueue *queue;
NSTimer *statusTimer;
__unsafe_unretained id<StatusControllerDelegate> delegate;
UIColor *first_color;
UIColor *second_color;
IBOutlet __unsafe_unretained UITableView *myTableView;
IBOutlet __unsafe_unretained UILabel *no_statuses_label;
IBOutlet __unsafe_unretained UIImageView *no_status_background;
#private
ICStatusViewControllerDoneCallbackBlock _doneCallbackBlock;
ICStatusViewControllerCancelCallbackBlock _cancelCallbackBlock;
}
#property (nonatomic, unsafe_unretained) UITableView* myTableView;
#property (nonatomic, copy) NSString* no_statuses;
#property (nonatomic, unsafe_unretained) UILabel* no_statuses_label;
#property (nonatomic, unsafe_unretained) id <StatusControllerDelegate> delegate;
#property (nonatomic, copy) ICStatusViewControllerDoneCallbackBlock doneCallbackBlock;
#property (nonatomic, copy) ICStatusViewControllerCancelCallbackBlock cancelCallbackBlock;
- (id)initWithStatus;
#end
You can either set the tint color of the navigation bar OR use a IMAGE instead of navigation bar and hide the navigation bar, using:
navigationController.navigationBarHidden = YES;
You are not talking about a UITableView, but about the UINavigationBar on the top. I fixed your question to reflect that. Basically there are two ways to set its tintColor:
The easier option would be to use the appearance protocol (iOS 5 and later), as this will change every NavigationBar in the whole app:
[[UINavigationBar appearance] setTintColor:[UIColor yellowColor]];
Or you do it on every single UINavigationBar of every UINavigationController.
[navigationController.navigationBar setTintColor:[UIColor yellowColor]];
just add this line for set yellow color to navigationcontroller in viewDidLoad: method of ICStatusViewController class..
[self.navigationController.navigationBar setTintColor:[UIColor yellowColor]];
and also with image like bellow..
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"yourImageName"] forBarMetrics:UIBarMetricsDefault];// write your image name like yellow image
i hope this help you...
What's your tableView's style? If tableView's style is UITableViewStyleGrouped, you can't change backgroundColor on iOS 6. Try to change tableView's backgroundView.
self.settingsTableView = [[UITableView alloc] initWithFrame:rect
style:UITableViewStyleGrouped];
UIView *view = [[UIView alloc] initWithFrame:settingsTableView.frame];
view.backgroundColor = [UIColor redColor];
settingsTableView.backgroundView = view;
Related
I have inherited some old iOS code and have attempted to integrate it into a new iOS 6 application. I have implemented most of the code and so far everything has worked. I'm now working on the last bit of that old code. I'm implementing a set of views to show a rss for a news section of my app. I've implemented the categories view, which upon selecting an item would display the individual items within that category. However nothing gets displayed. I've made all the modifications that I'm aware of that I needed to do, however I'm no expert at iOS development and am in need of some guidance. Below is a snapshot of the simulator as it's attempting to display the view, and below that is a copy of my .h and .m files. I don't know what is preventing anything in the table from showing up. And preemptive thanks to any help!
here's the snapshot of the simulator
Here is a snapshot of the storyboard showing the linking to the Table View
Here's the .h file
#import <UIKit/UIKit.h>
#import "BlogRssParser.h"
#class BlogRssParser;
#class BlogRssParserDelegate;
#class BlogRss;
#class XMLCategory;
#interface NewsViewController : UIViewController <UITableViewDataSource,UITableViewDelegate, BlogRssParserDelegate> {
BlogRssParser * _rssParser;
XMLCategory * _currItem;
}
#property (nonatomic, retain) BlogRssParser * rssParser;
#property (readwrite, retain) XMLCategory * currItem;
#property (nonatomic, retain) IBOutlet UITableView *itemTableView;
#end
Here is my .m file
#import "NewsViewController.h"
#import "NewsDetailsViewController.h"
#import "BlogRssParser.h"
#import "BlogRss.h"
#import "XMLCategory.h"
#define kLabelTag 1;
#interface NewsViewController ()
#end
#implementation NewsViewController
#synthesize rssParser = _rssParser;
#synthesize currItem = _currItem;
- (void)navBarInit {
UIBarButtonItem *refreshBarButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self action:#selector(reloadRss)];
[self.navigationItem setRightBarButtonItem:refreshBarButton animated:YES];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.itemTableView.delegate = self;
self.itemTableView.dataSource = self;
- (void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self navBarInit];
[self.itemTableView reloadData];
self.itemTableView.userInteractionEnabled = NO;
}
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
_rssParser = [[BlogRssParser alloc]init];
_rssParser.delegate = self;
[[self rssParser]startProcess:[_currItem categoryId]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)reloadRss{
[[self rssParser]startProcess:[_currItem categoryId]];
[[self itemTableView]reloadData];
}
- (void)processCompleted{
[[self itemTableView]reloadData];
// _tableView.userInteractionEnabled = YES;
[[self itemTableView]setUserInteractionEnabled:YES];
}
-(void)processHasErrors{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"My Title" message:#"Unable to retrieve the news. Please check if you are connected to the internet."
delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [[[self rssParser]rssItems]count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
const CGFloat LABEL_TITLE_HEIGHT = 70.0;
const CGFloat LABEL_WIDTH = 210.0;
NSString * mediaUrl = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]mediaUrl];
NSData * imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mediaUrl]];
UIImage * imageFromImageData;
if (imageData == nil) {
imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:#"http://www.urlForImage.image.png"]];
}
imageFromImageData = [[UIImage alloc] initWithData:imageData];
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:#"rssItemCell"];
if(nil == cell){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"rssItemCell"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
UILabel * _topLabel =
[[UILabel alloc]
initWithFrame:
CGRectMake(
imageFromImageData.size.width + 10.0,
0.0,
LABEL_WIDTH,
LABEL_TITLE_HEIGHT)];
_topLabel.tag = kLabelTag;
_topLabel.opaque = NO;
_topLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;
_topLabel.backgroundColor = [UIColor clearColor];
_topLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
_topLabel.highlightedTextColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.9 alpha:1.0];
_topLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]];
_topLabel.numberOfLines = 0;
[cell.contentView addSubview:_topLabel];
}
cell.imageView.image = imageFromImageData;
UILabel * topLabel = (UILabel *)[cell.contentView viewWithTag:1];
topLabel.text = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]title];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NewsDetailsViewController *tlc = [[DetailsViewController alloc]init];
tlc.currentItem = [[[self rssParser]rssItems]objectAtIndex:indexPath.row];
tlc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:tlc animated:YES completion:nil];
}
#end
I could not get a conclusion about the problem you are facing.
But here are few things you should check.
Because i cannot see even an empty table view in your screenshot
Do you have the TableView on the Nib file ?
It is mapped from The Nib file to the IBOutlet itemTableView ?
Add at least one table view cell (Drag and drop one prototype cell)..
like this
Then select that cell and give some name in "Reuse Identifier" with this identifier allow datasource..
First thing I would do is make sure that [[[self rssParser] rssItems] count] is actually returning > 0. Also, is this a copy&paste of your .m file? viewDidLoad is missing the closing brace, but Xcode would catch that.
I am slowly developing a custom button (while learning how to implement classes etc).
I have a ViewController, which imports a SuperButton.h (UIControl) and then creates an instance of the SuperButton. (This works, as proved by a NSLog.)
But I cannot get the method in SuperButton to display a Label.
I think this might have something to with the '.center' value or the 'addSubview' command?
I would really appreciate your help. Thanks.
Here is my SuperButton.m code:
#import "SuperButton.h"
#implementation SuperButton
#synthesize firstTitle;
#synthesize myLabel;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void) shoutName{
NSLog(#"My name is %#", firstTitle);
self.backgroundColor = [UIColor blueColor];
CGRect labelFrame = CGRectMake(0.0f, 0.0f, 100.0f, 50.0f);
self.myLabel = [[UILabel alloc] initWithFrame:labelFrame];
self.myLabel.text = #"Come on, don't be shy.";
self.myLabel.font = [UIFont italicSystemFontOfSize:14.0f];
self.myLabel.textColor = [UIColor grayColor];
self.myLabel.center = self.center;
[self addSubview:self.myLabel];
}
Here is the code in my ViewController:
- (void) makeButton{
SuperButton *button1 = [[SuperButton alloc] init];
button1.firstTitle = #"Mr. Ploppy";
[button1 shoutName];
}
(EDIT:) Just in case, here's the SuperButton.h code:
#import <UIKit/UIKit.h>
#interface SuperButton : UIControl
#property (nonatomic, strong) NSString *firstTitle;
#property (nonatomic, strong) UILabel *myLabel;
- (void) shoutName;
#end
I found an answer elsewhere.
I needed to addSubview the 'button'. My working code now looks like this:
- (void) makeButton{
SuperButton *button1 = [[SuperButton alloc] init];
button1.firstTitle = #"Mr. Ploppy";
[button1 shoutName];
[self.view addSubview:button1.myLabel];
[self.view sendSubviewToBack:button1.myLabel];
}
You are initializing your button not with initWithFrame: method, but with simple init. This makes the button of CGRectZero size. Change this line:
SuperButton *button1 = [[SuperButton alloc] init];
to this:
SuperButton *button1 = [[SuperButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 50.0f)];
or add a call to setFrame: after initializing your button.
i have a problem with my app crashing when my custom TableViewCell gets released.
the Cell gets initialized like the following in cellForRowAtIndexPath:
SearchTableViewCell *cell = (SearchTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[SearchTableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
cell.nameLabel.text = #"some text";
cell.addressLabel.text = #"some more text";
the cell class itself looks like this
#import <UIKit/UIKit.h>
#class EGOImageView;
#interface SearchTableViewCell : UITableViewCell {
UILabel *nameLabel;
UILabel *addressLabel;
EGOImageView *imageView;
}
#property (nonatomic, retain) UILabel *nameLabel;
#property (nonatomic, retain) UILabel *addressLabel;
- (UILabel *)labelWithColor:(UIColor*)color selectedColor:(UIColor*)selectedColor fontSize:(CGFloat)fontSize bold:(BOOL)bold frame:(CGRect)rect;
- (void)setThumb:(NSString*)thumb;
#end
.m
#import "SearchTableViewCell.h"
#import "EGOImageView.h"
#import "UIView+Additions.h"
#implementation SearchTableViewCell
#synthesize nameLabel = _nameLabel, addressLabel = _addressLabel;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
// Initialization code
UIView *myContentView = self.contentView;
// Name
_nameLabel = [self labelWithColor:[UIColor blackColor] selectedColor:[UIColor whiteColor] fontSize:16.0f bold:YES frame:CGRectMake(140.0f, 16.0f, 181.0f, 21.0f)];
[myContentView addSubview:_nameLabel];
[_nameLabel release];
// Adress
_addressLabel = [self labelWithColor:[UIColor blackColor] selectedColor:[UIColor whiteColor] fontSize:13.0f bold:YES frame:CGRectMake(140.0f, _nameLabel.bottom, 181.0f, 21.0f)];
[myContentView addSubview:_addressLabel];
[_addressLabel release];
// Image
imageView = [[EGOImageView alloc] initWithPlaceholderImage:[UIImage imageNamed:#"placeholder.png"]];
imageView.frame = CGRectMake(9.0f, 9.0f, 120.0f, 80.0f);
[myContentView addSubview:imageView];
[imageView release];
}
return self;
}
- (UILabel *)labelWithColor:(UIColor*)color selectedColor:(UIColor*)selectedColor fontSize:(CGFloat)fontSize bold:(BOOL)bold frame:(CGRect)rect {
UIFont *font;
if(bold) {
font = [UIFont boldSystemFontOfSize:fontSize];
} else {
font = [UIFont systemFontOfSize:fontSize];
}
UILabel *label = [[UILabel alloc] initWithFrame:rect];
label.backgroundColor = [UIColor clearColor];
label.textColor = color;
label.highlightedTextColor = selectedColor;
label.font = font;
return label;
}
- (void)setThumb:(NSString*)thumb {
imageView.imageURL = [NSURL URLWithString:thumb];
}
- (void)willMoveToSuperview:(UIView *)newSuperview {
[super willMoveToSuperview:newSuperview];
if(!newSuperview) {
[imageView cancelImageLoad];
}
}
- (void)dealloc {
[_addressLabel release];
[_nameLabel release];
[imageView release];
[super dealloc];
}
#end
does anybody have an idea why my app crashes on releasing such a cell? commenting out the 2 labels and the image view on dealloc method, the app doesn't crash, but then there will be a memory leak right?
thanks for all hints! please leave a comment if something is unclear!
imageView is being released twice, once when it is created:
imageView = [[EGOImageView alloc] initWithPlaceholderImage:[UIImage imageNamed:#"placeholder.png"]];
imageView.frame = CGRectMake(9.0f, 9.0f, 120.0f, 80.0f);
[myContentView addSubview:imageView];
[imageView release];
and once in dealloc:
- (void)dealloc {
[_addressLabel release];
[_nameLabel release];
[imageView release];
[super dealloc];
}
You already release the memory for that labels after adding to view,again you are trying to release memory those objects are already relese in dealloc method that's why it is killing.if you remove 3 statements in dealloc method it will not crash.
I think the Problem is that you release your properties direct in the initWithStyle function and additional to that in dealloc again. Try removing the release from initWithStyle:
Furthermore you named your variables without _ in the interface but with _ #synthesize'ing in the implementation
I'm completely new to iPhone development. I have a query regarding how to implement scroll view in table view. I'm using following code
#import <UIKit/UIKit.h>
#class ScrollViewViewController;
#interface ScrollViewAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
ScrollViewViewController *viewController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet ScrollViewViewController *viewController;
#end
////////////////////////////////////////////
#import "ScrollViewAppDelegate.h"
#import "ScrollViewViewController.h"
#implementation ScrollViewAppDelegate
#synthesize window;
#synthesize viewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
#end
///////////////////////////
#import <UIKit/UIKit.h>
#interface MyTableCell : UITableViewCell {
NSMutableArray *columns;
}
- (void)addColumn:(CGFloat)position;
#end
//////////////////////////
#import "MyTableCell.h"
#implementation MyTableCell
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
// Initialization code
columns = [NSMutableArray arrayWithCapacity:5];
[columns retain];
}
return self;
}
- (void)addColumn:(CGFloat)position {
[columns addObject:[NSNumber numberWithFloat:position]];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)drawRect:(CGRect)rect {
CGContextRef ctx = UIGraphicsGetCurrentContext();
// just match the color and size of the horizontal line
CGContextSetRGBStrokeColor(ctx, 0.5, 0.5, 0.5, 1.0);
CGContextSetLineWidth(ctx, 0.25);
for (int i = 0; i < [columns count]; i++) {
// get the position for the vertical line
CGFloat f = [((NSNumber*) [columns objectAtIndex:i]) floatValue];
CGContextMoveToPoint(ctx, f, 0);
CGContextAddLineToPoint(ctx, f, self.bounds.size.height);
}
CGContextStrokePath(ctx);
[super drawRect:rect];
}
- (void)dealloc {
[super dealloc];
[columns dealloc];
}
#end
//////////////////////
#import <UIKit/UIKit.h>
#interface RootViewController : UITableViewController {
}
#end
/////////////////
#import "RootViewController.h"
#import "MyTableCell.h"
#implementation RootViewController
#define LABEL_TAG 1
#define VALUE_TAG 2
#define FIRST_CELL_IDENTIFIER #"TrailItemCell"
#define SECOND_CELL_IDENTIFIER #"RegularCell"
- (void)viewDidLoad {
// Add the following line if you want the list to be editable
// self.navigationItem.leftBarButtonItem = self.editButtonItem;
self.title = #"Grids!";
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
return 19;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *MyIdentifier = [NSString stringWithFormat:#"MyIdentifier %i", indexPath.row];
MyTableCell *cell = (MyTableCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[MyTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 0, 30.0,
tableView.rowHeight)] autorelease];
[cell addColumn:40];
label.tag = LABEL_TAG;
label.font = [UIFont systemFontOfSize:12.0];
label.text =#"S.NO";// [NSString stringWithFormat:#"%d", indexPath.row];
label.textAlignment = UITextAlignmentRight;
label.textColor = [UIColor redColor];
label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:label];
label = [[[UILabel alloc] initWithFrame:CGRectMake(40.0, 0, 70.0,
tableView.rowHeight)] autorelease];
[cell addColumn:120];
label.tag = VALUE_TAG;
label.font = [UIFont systemFontOfSize:12.0];
// add some silly value
label.text =#"Product ID";// [NSString stringWithFormat:#"%d", indexPath.row * 4];
label.textAlignment = UITextAlignmentRight;
label.textColor = [UIColor blueColor];
label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:label];
label = [[[UILabel alloc] initWithFrame:CGRectMake(134.0, 0, 70.0,
tableView.rowHeight)] autorelease];
[cell addColumn:220];
label.tag = VALUE_TAG;
label.font = [UIFont systemFontOfSize:12.0];
// add some silly value
label.text =#"Product Name";// [NSString stringWithFormat:#"%d", indexPath.row * 4];
label.textAlignment = UITextAlignmentRight;
label.textColor = [UIColor greenColor];
label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:label];
label = [[[UILabel alloc] initWithFrame:CGRectMake(230.0, 0, 70.0,
tableView.rowHeight)] autorelease];
[cell addColumn:310];
label.tag = VALUE_TAG;
label.font = [UIFont systemFontOfSize:12.0];
// add some silly value
label.text =#"Customer Name";// [NSString stringWithFormat:#"%d", indexPath.row * 4];
label.textAlignment = UITextAlignmentRight;
label.textColor = [UIColor greenColor];
label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:label];
label = [[[UILabel alloc] initWithFrame:CGRectMake(320.0, 0, 70.0,
tableView.rowHeight)] autorelease];
[cell addColumn:400];
label.tag = VALUE_TAG;
label.font = [UIFont systemFontOfSize:12.0];
// add some silly value
label.text =#"Customer Product";// [NSString stringWithFormat:#"%d", indexPath.row * 4];
label.textAlignment = UITextAlignmentRight;
label.textColor = [UIColor greenColor];
label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:label];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
}
- (void)viewDidDisappear:(BOOL)animated {
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[super dealloc];
}
#end
////////////
#import <UIKit/UIKit.h>
#interface ScrollViewViewController : UIViewController<UIScrollViewDelegate> {
}
#end
/////////////
#import "ScrollViewViewController.h"
#import "RootViewController.h"
#implementation ScrollViewViewController
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
RootViewController *RootViewControllerLink = [[RootViewController alloc]initWithNibName:#"RootViewController" bundle:nil];
RootViewControllerLink.view.tag = 100;
/* UIImageView *imgView = [[[UIImageView alloc] initWithImage:
[UIImage imageNamed:#"winkler-gnu-blue.png"]] autorelease];
imgView.tag = 100;
*/
UIScrollView *scrollView = [[[UIScrollView alloc]
initWithFrame:CGRectMake(0,0,320,480)] autorelease];
scrollView.delegate = self;
scrollView.minimumZoomScale = 0.25;
scrollView.maximumZoomScale = 2;
scrollView.bounces = NO;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.contentSize = RootViewControllerLink.view.frame.size;
scrollView.contentOffset =
CGPointMake((RootViewControllerLink.view.frame.size.width-320)/2,
(RootViewControllerLink.view.frame.size.height-480)/2);
[scrollView addSubview:RootViewControllerLink.view];
self.view = scrollView;
}
/*- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return [self.view viewWithTag:100];
}
- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
{
return YES;
}// default returns YES
- (BOOL)touchesShouldCancelInContentView:(UIView *)view
{
return YES;
}
*/
// not called if canCancelContentTouches is NO. default returns YES if view isn't UIControl
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
In above code if I set scroll for UIIMage then it works but if I set scroll view for RootViewController then it doesn't work.
I didn't read your code, please reformat it so others can read it easily.
What do you mean by a UIScrollView in an UITableView? Inside the cells? Still I don't get it.
FYI UITableView inherits from UIScrollView ...
What functionality do you exactly want to achieve?
I will recommend to read some of the samples given by Apple. There are very good and extensive examples specially regarding UIKit.
I have the following problem:
There is a class that includes five tabs in the following way:
mainMenuClient.h
#import <UIKit/UIKit.h>
#interface MainMenuClient : UIViewController {
UITabBarController *tabBarController;
}
#property (nonatomic, retain) UITabBarController *tabBarController;
#end
mainMenuClient.m
-(void)viewDidLoad {
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor blackColor];
self.view = contentView;
[contentView release];
ContactListTab *contactTab = [[ContactListTab alloc] init];
ChatTab *chat = [[ChatTab alloc]init];
DialerTab *dialer = [[DialerTab alloc]init];
MenuTab *menu = [[MenuTab alloc]init];
TesztingFile *teszting = [[TesztingFile alloc]init];
contactTab.title = #"Contact List";
chat.title = #"Chat";
dialer.title = #"Dialer";
menu.title = #"Menu";
teszting.title = #"TesztTab";
contactTab.tabBarItem.image = [UIImage imageNamed:#"Contacts_icon.png"];
chat.tabBarItem.image = [UIImage imageNamed:#"Chat_icon.png"];
dialer.tabBarItem.image = [UIImage imageNamed:#"Dialer_icon.png"];
menu.tabBarItem.image = [UIImage imageNamed:#"Menu_icon.png"];
teszting.tabBarItem.image = [UIImage imageNamed:#"Contacts_icon.png"];
chat.tabBarItem.badgeValue = #"99";
tabBarController = [[UITabBarController alloc]init];
tabBarController.view.frame = CGRectMake(0, 0, 320, 460);
[tabBarController setViewControllers:[NSArray arrayWithObjects:contactTab, chat, dialer, menu, teszting, nil]];
[contactTab release];
[chat release];
[dialer release];
[menu release];
[teszting release];
[self.view addSubview:tabBarController.view];
[super viewDidLoad];
}
In the contactTab class there are a UITableViewController.
contactTab.h
- (void)updateCellData;
- (void)configureCell:(UITableViewCell *)cell forIndexPath:(NSIndexPath *)indexPath;
There is a third class, which I would like to achieve is a method of UITableViewController's (from ContactTab).
So far I tried this:
When I tried to achieve the UItabbarController:
MainMenuClient *menu;
UITabBarController *tabBarControllerchange = [[UITabBarController alloc] init];
tabBarControllerchange = menu.tabBarController;
[tabBarControllerchange setSelectedIndex:0];
When I tried to achieve the UITableViewController:
ContactListTab *contactListTab;
[contactListTab updateCellData];
Does anybody have an idea for this problem? Thanks. Balazs.
You need to get the instance of your MainMenuClient:
define method in your MainMenuClient.h as:
+(MainMenuClient*)getMainMenuInstance;
Implement the following method in MainMenuClient.m as :
+(MainMenuClient*)getMainMenuInstance
{
return self;
}
Now you can get same instance of UITabBarContrtoller in any class as :
MainMenuClient *menuClient = [MainMenuClient getMainMenuInstance];
UITabBarContrtoller *newTabBarController = menuClient.tabBarController;
You can do what ever you want to do with this new UITabBarController object.
Hope this helps.
Jim.