Archive

Archive for the ‘Coding’ Category

gCalWall Updates

April 23rd, 2009

gCalWall_128.png

I just wanted to throw up a quick post on the current state of gCalWall. I know there’s some things that are a little “wonky”. Some (minor number) of folks have seen issues with all day events, and some other stuff like blurry images. I have every intention of doing everything I can to fix these issues. I also have every intention of working in some requested improvements. But at the same time, I haven’t made much of anything off of gCalWall wall – so while its a product I intend to continue working on, it’s not a “top” priority.

So, long story short – I’m working on it, but I wouldn’t expect to release anything (aside from a major affects everybody emergency bugfix) until the iPhone 3.0 software is released. Why? Well, there’s some things I have to change for gCalWall in 3.0 to work properly and I’ve already got a development build started. So, rather than try and maintain separate builds, I’m jumping ship from 2.x and moving on to 3.x…

brandon Coding, iPhone

Building an iPhone App Without Interface Builder

February 25th, 2009


Building iPhone Applications without Interface Builder from Troy Mcilvena on Vimeo

Adding this one for my own future reference. The important things to note was really how to remove the references to the NIB files when first building the project.

In the Resouces like locate the info.plist file and right click then go to source view and delete:

key - NSMainNibFile
string - MainWindow

While you’re in he resources list also delete the mainWindow.xib file. Finally open “Other Sources” main.m and you’re going to edit this line:

int retVal = UIApplicationMain(argc, argv, nil, nil);

and make it look like this:

    int retVal = UIApplicationMain(argc, argv, nil, @"Your_App_Delegate_Class");

That pretty well sums up the key points. There’s some good information about UIWindow and UIView in the video as well if you’re not familiar with building your base view without IB. gCalWall was built largely without using Interface Builder at all so I was pretty familiar with most of it.

brandon Coding

Excellent iPhone Email App Tutorial

February 25th, 2009


iphone programming from Joe on Vimeo

Definitely worth the time to watch. Make sure you click on through and say thanks to Joe!

brandon Coding ,

NSCFArray append string errors, distinct Objective-C types

January 22nd, 2009

Picture 1.png

Ran into some weirdness earlier which was absolutely killing me. I’m building a project using SQLite Persistent Objects, and this:

NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
	dict = [Commands sortedFieldValuesWithKeysForProperty:@"commandname"];
	self.keyLookup = [dict mutableDeepCopy];

	NSMutableArray *array = [[NSMutableArray alloc] init];
	array = [[[self.keyLookup allValues] sortedArrayUsingSelector:@selector(compare:)] retain];

was throwing an error about assigning the values from a distinct Objective-C type. I was able to fake my way around it in another viewController I had a similar issue with, but this time it was a show stopper because when I tried to work with the resulting array later (by adding/removing some stuff from it) I would get another error:

exception: *** -[NSCFArray addObject:]: mutating method sent to immutable object

Well, I was pretty dammed sure I hadn’t asked for my array to be immutable, but I’m guessing somewhere in the code for the persistent object (which I’ll be checking into) there’s a copy happening (or something similar) and its turning the returned data into an NSCFArray. To fix it… I needed to make it a mutable array again:

if (self.commandArray != array){
		[self.commandArray release];
		self.commandArray = [array mutableCopy];

Of course this may be simple if you’re the programming type… but it drove me nuts for a while!

brandon Coding

UISearchBar to be the top item in the view

January 22nd, 2009

Picture 1.png

So what to do if you’re building a view and you have a navigationBar at the top of the view but you want a searchbar at the top instead?

Try this in your viewDidLoad:

 self.navigationController.navigationBar.topItem.titleView = searchBar;

Of course you’ll need to define searchBar in the header file too…

IBOutlet UISearchBar *searchbar;

Along with doing all the NIB file stuff, property declarations, blah blah blah… but you get the idea.

brandon Coding

Had to write a VBScript today

January 13th, 2009

003_p5_det_c
Creative Commons License photo credit: wisof

Had to write a VBScript today to do some funky stuff. Basically we needed to copy in a string of text and then output that text so it would be formatted to go into an email.

Input text looked something like:

x.x.x.0/x Company  How Assigned    Location

The big issue I had with all of this is that there’s spaces in the company names, spaces in the location, spaces in how assigned… so I couldn’t use a space as the delimter. Well, the code is UGLY… but the general concept is I knew I had certain points where I would have more than one space in a row. After the company name I had 2 spaces. After the How assigned I had 4 spaces. So I could create a couple arrays and delimit using those known values. The only other problem I had was how to get rid of the IP address before the company name… well I solved that by getting rid of all the numbers from the section of the array where the company should be. Again this isn’t pretty – but it got the job done.

window.resizeTo 450,500

dim arrHeaders(3), strIP, strCompany, strStatus, strNewContent
arrHeaders(0) = "IP Block:"
arrHeaders(1) = "Customer:"
arrHeaders(2) = "Status:"
arrHeaders(3) = "IDC:"

Sub SetCopyPaste

strPortal = "From the site:"

strline = CopyPaste.value
arrFields = Split(strLine)
arrFields2 = Split(strline, "  ")
cutString = arrFields2(0)
arrFields3 = Split(strline, "    ")

strAlphaNumeric = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
For i = 1 to len(cutString)
strChar = mid(cutString,i,1)
If instr(strAlphaNumeric,strChar) Then
CleanedString = CleanedString & strChar
End If
next

strIP = arrFields(0)
strCompany = CleanedString
strStatus = arrFields2(1)
strIDC = arrFields3(1)
strNewContent = strPortal & vbCrLf & vbCrLf & arrheaders(0) & " " & strIP & " - " & strStatus & vbCrLf _
& arrHeaders(1) & " " & strCompany & vbCrLf & arrheaders(3) & " " & strIDC

CombinedText.Value = strNewContent

End Sub

Obviously there’s VBSCRIPT tags at the top and the bottom… and some HTML to format the page.

The attached file you can grab and see the whole thing with the code and whatnot.

Output text looked like this:
From the site:

IP Block: x.x.x.0/x – How Assigned
Customer: Company
IDC: Location

spam-email

brandon Coding

TabBarViewController with TableViews

January 10th, 2009

Coding can kill
Creative Commons License photo credit: databhi ♪♫

Here’s the solution to that generic problem of creating a tabBarController that has Navigation Controllers / tableViews under each tab.

(SOURCE LINK – See posts 5 & 8 )

Here's the code. Reposted for my future reference in case the source disappears. 

@interface AppDelegate : NSObject  {
    UIWindow *window;
    UITabBarController *tabBarController;
    MyTableViewController *myTableViewController;
    MySecondTableViewController *mySecondTableViewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) UITabBarController *tabBarController;
@property (nonatomic, retain) MyTableViewController *myTableViewController;
@property (nonatomic, retain) MySecondTableViewController *mySecondTableViewController;

@end

@implementation AppDelegate

@synthesize window, myTableViewController, mySecondTableViewController, tabBarController;

- (void)applicationDidFinishLaunching:(UIApplication *)application {

       tabBarController = [[UITabBarController alloc] init];          // creates your tab bar so you can add everything else to it

       myTableViewController = [[MyTableViewController alloc] init];               // creates your table view - this should be a UIViewController with a table view in it, or UITableViewController
       UINavigationController *tableNavController = [[[UINavigationController alloc] initWithRootViewController:myTableViewController] autorelease];
       [myTableViewController release];                                                              // creates your table view's navigation controller, then adds the view controller you made. Note I then let go of the view controller as the navigation controller now holds onto it for me. This saves memory.

       mySecondTableViewController = [[MySecondTableViewController alloc] init];
       UINavigationController *table2NavController = [[[UINavigationController alloc] initWithRootViewController:mySecondTableViewController] autorelease];
       [mySecondTableViewController release];                                                    // does exactly the same as the first round, but for your second tab at the bottom of the bar.

       tabBarController.viewControllers = [NSArray arrayWithObjects:tableNavController, table2NavController, nil]; add both of your navigation controllers to the tab bar. You can put as many controllers on as you like, but they will turn into the more button like in the iPod program.

       [window addSubview:tabBarController.view];                                              // adds the tab bar's view property to the window
       [window makeKeyAndVisible];                                                                  // makes the window visible
}

- (void)dealloc {
       [tabBarController release];
       [window release];
       [super dealloc];
}                                           // lets go of everything else, thats so your program doesn't create any leaks of memory.

@end

brandon Coding

AppDelegate –

January 10th, 2009

2007-06-11-14-57-24
Creative Commons License photo credit: sonicwalker

So, for the past few days I’ve been pulling my hair out (because I’m not a programmer so this is all new to me). I was having a really hard time with figuring out why even if I had a class named AppDelegate, and I had all the methods I needed in that AppDelegate class I would get exceptions thrown at runtime because I was requesting something my tableview controller that it didn’t have. Drove me bananas trying to figure out why the tableview controller was responding and throwing errors when I knew the AppDelegate class has the right stuff.

Turns out there was one little problem with my understanding of the Model-View-Controller concept – and its this:

You can have as many classes as you want, and you can call them all kinds of things including AppDelegate, but only one of them is actually going to be the app delegate – and it’s the one that has this little line in it:

@interface AppDelegate : NSObject <UIApplicationDelegate> {

// notice the part where it conforms to UIApplicationDelegate. That’s the key!

I gleaned this little jem of information in an explanation from (another) Brandon here:

The AppDelegate is basically your application’s controller. It is where execution begins (other than main.m). That line was put into place to access the AppDelegate object. This was to get a reference to the “fruits” array. The “fruits” array was declared inside of our application’s delegate.
Here it is line by line

FruitAppDelegate *appDelegate

// Declaring an object to hold the reference to the applicaiton’s appDelegate

(FruitAppDelegate *)

// We are casting the return value of the next phrase to a FruitAppDelegate

[[UIApplication sharedApplication] delegate]

// This gives us a reference to the appDelegate for the whole application

now that the appDelegate object holds a reference to the application’s appDelegate object, we can access variables that are declared inside of it. This allows us to do things like [appDelegate.fruits count] which will return the number of fruits in the array.
I hope that helps…

So they key to all of this – is AppDelegate isn’t that class you smartly named AppDelegate. The AppDelegate was defined when you started the project.

brandon Coding

Twitter links powered by Tweet This v1.6.1, a WordPress plugin for Twitter.