table view show a new specifik table view - iphone

so i have this app that is a training program in this app the first screen is a tableview that has to contain some programs then when the user clicks on the table it loads the programs again in a tableview and show what exercises there is in this program
but i can't find a why to make the program decide what program the user selected and then repressed the right exercises table
i alsov need a why to save all this data to a file ore if there is a better why to save the data pleas tell me.
alsov the add button is not completely don atm it just starts a new view where the user can enter name a off the program and when the user is inside the program it alsov can enter times but there i have the problem that i need to get the data from the add screen to the table view so i can create the cell
sry for my english
pleas rember that im a noob programmer when you answere

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
this method will tell the code which row is selected by user

Related

iPhone master detail app how to use detail view to change the text value displayed in the corresponding cell in the master view

I am brand new to iOS programming and am currently taking an iOS class at school. For a project that I am doing we have to write a basic master-detail application for iPhone. For my app, I am creating a simple to do list type of app. The name of each task is displayed in the master view, the name of the task can be changed in the detail view. I set up a save button that has an unwind segue delegate when pressed. When i press the button I segue back to the master view I cannot get the value of the corresponding cell to change in real time. I know that it the master view is getting the changed information back because the changed information doesn't get saved until control transfers back to the master view and it is getting saved. When I rerun the app, the new name is displayed instead of the default name.
here is the delegate for the unwind segue
- (IBAction) done:(UIStoryboardSegue *)segue
{
// index for the cell in the master view table that was changed
NSIndexPath *changeIndex = [self.tableView indexPathForSelectedRow];
[self tableView:self.tableView cellForRowAtIndexPath:changeIndex];
// place the new dictionary entry created by the detail view in the location of the
// array where the old entry was located
_taskList[changeIndex.row] = self.ChangedEntry;
// store the change in the plist file
[_taskList writeToFile:self->documentPlistPath atomically:YES];
}
which calls this function, which appears to change the text for a cell in a table but I'm not sure
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
cell.textLabel.text = _taskList[indexPath.row][TASK_DATA_NAME];
return cell;
}
So yeah, I am just trying to figure out how to make the master view reflect changes made in the detail view without having to close the app and reopen it. Oh and I am using Xcode 5 and targeting iOS 7.
Basically, after you update your data model (_taskList) you need to refresh the table view by calling reloadData on it. This tells it to update all of the rows.

Developing a simple Course Management System for iPhone using Xcode using Table Views only

I have to build a Course management app. I am using table views only for this app. Using the table view controllers.
The first view contains the semesters - 1,2,3,4....12.
The second view contains details that are respective to the previous table view controller.
The details in the second table view controller are: Lectures, Papers, To-do list, Record lecture.
Depending on the user's selection, he can access Lectures, Papers, List, Record Lecture for that particular semester.
I am not able to figure out how to pass data from the third view to the fourth and subsequent views. For eg. Lecture->Lecture 1: Introduction->Download PDF.
How do I assign a specific table view controller when the user taps a particular cell? using seques or cellForRowAtIndexPath method?
I am confused.
Kindly help me in this regard. Your help will be highly appreciated.
You will do that in the didSelectRowAtIndexPath. Here you prepare the view you want to present and push it into the your navigationController. For instance:
// On user tap, present the details you want.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *detail = [[DetailViewController alloc] initWithDictionary:dict];
[self.navigationController pushViewController:detail animated:YES];
}
Additionally, these are some relevant links for what you are trying accomplish:
-Navigation Controllers
-Table Views
Do the selection part in
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

Change a tableview entry

Say I have an iPhone app using a tableview. As shown below, if I click the edit button I go into edit mode. Then I have the option to delete or add. So far so good, and all of my code is working. However, what about modifying one the the cells?
The first cell, for example, is Chevy. Say I want to change it to Ford. How can I edit a cell's value while in edit mode?
Is there another button I can add called "Change"? If so what would the code be for this?
Having looked around Google I can't find any results for this type of question. Does anyone know any good tutorials? Or at the very least, can someone provide some ideas and perhaps code samples to get started?
Depends how you want the user experience to be. One option would be to use the TableView delegate method didSelectRowAtIndexPath to take the user to another page with a text field and a save button.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UIViewController* myEditCarDetailsViewController = [[UIViewController alloc] init]
[self.navigationController pushViewController:myEditCarDetailsViewController animated:YES];
}
Once the user clicked save, you just need to update the datasource and call reloadData on the tableView.
Another option would be to make a custom tableView cell that has a textField in it that you set to editable when the table is in edit mode.
I'm guessing you were hoping for an in built apple way. I don't know of one, but it may exist

RunLoop with UITableView lock up

I'm writing an iPad app and have a problem with ui responsiveness / lock up.
I have a UITableView with items, when an item is clicked, it goes out on the internet and fetches that item and displays it. The rest of the program (not shown) will use the item downloaded, so only one item can be downloaded at a time.
Fetching the item can take a long time. During that time I want the user to still be able to scroll around the UITableView, but not to be able to select anything until the previous item clicked has been downloaded.
I know this can be done using threads,blocks, and callbacks, but right now I don't have time to do that (impossible time constraint).
I thought a quick way would be to download it sequentially and use run loops and a flag like this two step process:
When the user clicks on a table cell didSelectRowAtIndexPath is called, in there I set a global flag, then call the download method to download the item. If the user clicks on another item (before the download is completed, it will see the flag checked and exit that function without downloading anything. Basically this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
static BOOL alreadyInHere=FALSE;
if (alreadyInHere) return;
alreadyInHere=TRUE;
....
downloadItem(...);
ShowAndUseItem(...);
alreadyInHere=FALSE;
}
This allows the user to select only one item at a time.
To allow the user to be able to still scroll around the UITableView during the long download, I put in a run loop in the downloadItem(...) method shown above like this...
-(void) downloadItem(....)
{
BOOL downloading=TRUE;
callFunctionsToStartdownload(...); //
while (downloading) {
downloading=DownloadSomeBytes(...);
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5, YES);
}
}
The result of (1) and (2) is that the user can still scroll around the UITableView during the sequential download, the alreadyInHere flag prevents them from selecting something and starting another download.
This works in most cases, but around 50% of the time, during the download, the UITableView becomes unresponsive (can't scroll to other items in the table), and even after the download didSelectRowAtIndexPath is never called again when you click on something making theUITableView basically locked up.
My question is, did I do the runLoop correctly?
I know there are other ways to do it, but I have to do it using this general method for now because of other reasons.
Thanks
You should not try to download or do any other potentially long activity in youR tableview didSelectRow method. Exit (return) from this UI method after setting up an asynchronous download so that you don't lock up the UI.
Locking out simultaneous downloads is still ok, but you want be careful to reset state after errors or timeouts.

Save current data from UITableView

Trying to figure out how data storage from UITableViews is ment to work. What is good practices when saving a UITableView data on e.g. viewDidDisappear.
Do I have to update an array with every changes made while working in the view, or can I collect all current values form the table on exit view?
Can someone point me in the right direction?
Thanks!
First, on when to save the data, I would suggest you save your data in this method instead of viewDidDisappear:.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Second, there are a bunch of ways to store data in iPhone applications, such as plist or sqlite3 database.
You are thinking about the problem the wrong way around. The UITableView only displays the data currently on screen. Its not a place to ever collect data from (other than user interaction which you should collect when they interact - didSelectRowAtIndexPath). Spend some time reading up on Model View Controller. The UITableView data should have COME from a model - the view should simply display it - so there is nothing to collect.