Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 11, 2006, 10:23 AM   #1
Soulstorm
macrumors 68000
 
Soulstorm's Avatar
 
Join Date: Feb 2005
Cocoa problem: What am I missing here?

I am trying to create a program that will hold the program of the lessons in my university for the 7 days of the week. For each day, it will display the lessons I have in the tableView, and for each lesson, it will hold the assignments I have for the specified lesson.



Here is my problem, I will tell you what to do in order to reproduce it:

--for Monday, create a new lesson
--For this lesson, change the assignment by typing anything you want into the textview and then pressing the "Add Assignment" button.

Note that when you click the "Show Item Info", the info is displayed correctly (even in the console behind the program).

--Now, if you try to show the info for the newly created element, it will be displayed correctly, but when you try to display the info for the first element again, the Assignments is GONE! Just like that. It has been replaced by the assignments of the second element.

Please, can someone help me, because I have been spending hours on this, and I still can't figure out what the problem is!

Here is the entire project: http://att.macrumors.com/attachment....1&d=1155316382

I would appreciate any recommendation or help.

EDIT: I fixed the link so that now the correct program is uploaded.
Attached Thumbnails
Click image for larger version

Name:	Picture 1.png
Views:	602
Size:	119.7 KB
ID:	54813  
Attached Files
File Type: zip cocoaki 3.zip (104.1 KB, 19 views)

Last edited by Soulstorm; Aug 11, 2006 at 12:18 PM.
Soulstorm is offline   0 Reply With Quote
Old Aug 11, 2006, 12:01 PM   #2
logicat2001
macrumors regular
 
Join Date: Apr 2003
Location: Minneapolis, MN
Soulstorm,

The project you uploaded is not the same as the one you're having problems with. Check it.

Best,
Anton
logicat2001 is offline   0 Reply With Quote
Old Aug 11, 2006, 12:13 PM   #3
Soulstorm
Thread Starter
macrumors 68000
 
Soulstorm's Avatar
 
Join Date: Feb 2005
Oh my God, I'm terribly sorry. I changed the link so that it reflects the actual program. You should be able to download it now...
Soulstorm is offline   0 Reply With Quote
Old Aug 11, 2006, 03:12 PM   #4
HiRez
macrumors 601
 
HiRez's Avatar
 
Join Date: Jan 2004
Location: Western US
You've got a few issues here. The fiesrt is that the line [assignmentText setString:str]; (in your showItemInfo method) was commented out, therefore nothing would display.

Also, when you're setting attributes from the GUI, you generally don't want to take the string directly because the string that the object refers to could be changed behind your back later on, and that's what appears to be happening here. Copy small strings when assigning them unless you have a good reason not to. Also, in your setter methods you want to be careful of releasing an object first because what happens when you try to assign the same object to itself (it'll happen, trust me)? You'll release the object before it can be assigned and be accessing freed memory (bad!). I've rewritten your assignment setter like this:
Code:
-(void)setLessonAssignments:(NSString *)theString {
    if (lessonAssignments != theString) {
         [lessonAssignments release];
         lessonAssignments = [theString copy];
    }
    NSLog(@"Setting the new assignments to: %@", lessonAssignments);
}
Note that I check first to make sure we're not trying to assign the same thing and do nothing if so. Also note I'm using NSLog instead of printf. If you're doing objective-C programming, NSLog is your friend, use it in most places you'd use printf (the %@ formatter code prints objects by calling their -description: method on them, which for strings is simply the string). Also note that the format string in NSLog statements must be an objective-c string (@"") or it will crash.

Finally I will say the interface is a bit goofy with having to click on the Show Item Info button to change the display (which is the same text field used to set new assignments). The whole thing as you have it now could be simplified by binding the text field to the selected row's assignment text, which would both automatically set it as you type and change the display when you click on a new row in your table.

EDIT: I took out a line that shouldn't have been in there.
__________________
Go outside, the graphics are amazing!

Last edited by HiRez; Aug 11, 2006 at 03:23 PM.
HiRez is online now   0 Reply With Quote
Old Aug 12, 2006, 03:05 AM   #5
Soulstorm
Thread Starter
macrumors 68000
 
Soulstorm's Avatar
 
Join Date: Feb 2005
Hirez, you are my hero. That sure solved my problem.

You are absolutely right the interface is goofy, I had originally intended using the method you described it. But when I saw it had problems, I tried to isolate some functions to find out what the problem was exactly.

One question about your method, though. I don't understand this statement:

Quote:
Originally Posted by HiRez
The whole thing as you have it now could be simplified by binding the text field to the selected row's assignment text...
Which text is that? And How can I bind it? Do you mean Cocoa Bindings? I tried changing the following function to this:
Code:
-(id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn
		   row:(int)row
{
	NSString *identifier = [tableColumn identifier];
	lesson *item = [[[Days objectAtIndex:currentDayID]dayLessons]objectAtIndex:row];
	
	[item takeValue:[assignmentText string] forKey:@"lessonAssignments"];
	[assignmentText setString: [item lessonAssignments]];
	
	return [item valueForKey:identifier];
}
but problems occured (I knew it was wrong at the time I was writting it, but a shot never hurts ).

Can you help me a little bit more?
Soulstorm is offline   0 Reply With Quote
Old Aug 14, 2006, 06:34 AM   #6
Soulstorm
Thread Starter
macrumors 68000
 
Soulstorm's Avatar
 
Join Date: Feb 2005
I have another problem that I cannot trace with my application.

This is the problem and the steps I follow to repdroduce it:


-click the '+' button to add a new lesson
-Select the new lesson and change the assignment to "Hello world" (or anything else) and click the "Add Assignment" button
-Select the initial lesson (the 'test').
-Select the newly created lesson
-Click the NSTextView and.... see the log!

Code:
[Session started at 2006-08-14 14:28:05 +0300.]
2006-08-14 14:28:05.736 cocoaki 3[426] Setting the new assignments to: Initial lesson assignment!
02006-08-14 14:28:10.066 cocoaki 3[426] Setting the new assignments to: No Assignments have been recorded yet...
2006-08-14 14:28:17.523 cocoaki 3[426] Setting the new assignments to: hello wotrld!
2006-08-14 14:28:24.297 cocoaki 3[426] -[NSBigMutableString characterAtIndex:] called with out-of-bounds index. For apps linked on Tiger this will raise an exception. For earlier apps it will produce this one-time warning and continue with existing behavior (which is undefined).
2006-08-14 14:28:24.298 cocoaki 3[426] *** -[NSBigMutableString characterAtIndex:]: Range or index out of bounds
Also, I should mention that I am facing other problems with the TextView. after I have added an assignment and try to change it by selecting the textview, the textview changes its contents to the assignment of the previewsly selected item!

Can anyone tell me hat the problem is? The project is included in my attachments... Any help would be greatly appreciated!
Attached Thumbnails
Click image for larger version

Name:	Picture 1.png
Views:	495
Size:	41.0 KB
ID:	55019  
Attached Files
File Type: zip cocoaki 3.zip (178.7 KB, 4 views)
Soulstorm is offline   0 Reply With Quote
Old Aug 15, 2006, 01:20 AM   #7
slooksterPSV
macrumors 68030
 
Join Date: Apr 2004
Location: Nowheresville
Send a message via AIM to slooksterPSV Send a message via MSN to slooksterPSV Send a message via Yahoo to slooksterPSV
Use CoreData - want me to link you to a great tutorial? I made two apps in less than 2 hours - 1 a recreate of MDM - MoneyData Manager, and now ADM - Assignment Data Manager. Here's a screen of ADM, then the link to the CoreData tutorial:
http://developer.apple.com/cocoa/coredatatutorial/

Oh sure, I find an error in my program just now
Attached Thumbnails
Click image for larger version

Name:	Picture 1.png
Views:	17
Size:	38.0 KB
ID:	55080  
__________________
AMD Phenom 9600, 2GB RAM, 250GB HDD, ATI Radeon 4850, Vista Home Premium 64-bit
Gateway NV53 with Windows 7 Home Premium 64-bit & Ubuntu 10.04 Lucid Lynx 64-bit
slooksterPSV is offline   0 Reply With Quote
Old Aug 15, 2006, 02:07 AM   #8
Soulstorm
Thread Starter
macrumors 68000
 
Soulstorm's Avatar
 
Join Date: Feb 2005
Thanks a lot. I will try CoreData, since I keep hearing everyone telling me to do so. Is CoreData really that great, I wonder...?

Anyway, thanks for the advice, but does anyone have a solution in my problem?
Soulstorm is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Problem with ResKnife Cocoa !!! Mac Basics and Help 0 Apr 18, 2014 12:36 PM
Missing files on external drive (big problem) ScottR iMac 0 Jun 11, 2013 01:35 PM
Missing Operating System Problem? .Impact Windows, Linux & Others on the Mac 0 Jun 8, 2013 08:11 PM
Problem With Missing PlugIn maclionlyc Mac OS X 10.7 Lion 0 Jan 2, 2013 02:08 PM
Storage Problem, Missing Gigabytes Help! DiScO197 MacBook Pro 2 Dec 8, 2012 10:42 AM

Forum Jump

All times are GMT -5. The time now is 03:20 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC