2

See update below.

I'm writing a tweak and am using AppList. I am hooking into spotlight and creating a table off all installed applications. I am trying to use the dataSource to get the information (display identifier etc). The problem is if dataSource is defined... I get the following error:

SpringBoard[1622] <Warning>: *** Assertion failure in -[NSIndexPath row], /SourceCache/UIKit/UIKit-2380.17/UITableViewSupport.m:2680 SpringBoard[1622] <Warning>: ***** AltKeyboard Uncaught Exception: Invalid index path for use with UITableView. Index paths passed to table view must contain exactly two indices specifying the section and row. Please use the category on NSIndexPath in UITableView.h if possible. *****
or
SpringBoard[1890] <Warning>: ***** AltKeyboard Uncaught Exception: *** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1] ***** SpringBoard[1890] <Error>: *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]' *** First throw call stack:

If dataSource is not defined and I use fake data (test name), the table is generated fine. When I print the dataSource there are only two items in it.

Ryan Petrich, on IRC, seemed to suggest that I was doing everything completely wrong but wasn't much help after that. Perhaps I am going about solving this problem incorrectly?

Code: http://pastebin.ca/2457626
Repository: https://github.com/twodayslate/ListLauncher

edit/update! dataSource is giving me problems. It isn't fetching the same number of apps and thus I am getting index errors and the like. I have over 200 apps but dataSource is only fetching 2.
The following code gives no errors but only displays 2 items: http://pastebin.ca/2458961

edit! I changed it so I just use ALApplicationList. I am able to get all the applications listed. However, when I attempt to scroll through the table, it crashes. Sorting and creating the list is really slow so I believe that might be causing the problem. I'm no pro at obj-c so I'm sure there is a better way than what I am doing. http://pastebin.ca/2459318

twodayslate
  • 2,803
  • 3
  • 27
  • 43
  • 1
    possible duplicate of [Cannot get deleteRowsAtIndexPaths to work](http://stackoverflow.com/questions/8774091/cannot-get-deleterowsatindexpaths-to-work). The answer there is applicable to this question, as the root cause of the exception is identical. – CodaFi Sep 24 '13 at 04:48
  • I never create the NSIndexPath so I believe this is different than the above solution – twodayslate Sep 24 '13 at 04:50
  • 1
    Don't be so sure of that. Line 164 in the pastebin link seems suspect to me. – CodaFi Sep 24 '13 at 04:51
  • Replacing line 164 with `NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:s];` still gives me http://pastebin.ca/2457632 – twodayslate Sep 24 '13 at 05:00
  • Okay, now fix your array access with a little bounds checking. – CodaFi Sep 24 '13 at 05:02
  • I have 237 apps installed on my device. dataSource seems to only have two things in it. Which is why it would give me this error. It is trying to find apps 3-237 but dataSource is having a fit. Right? – twodayslate Sep 24 '13 at 05:05
  • Included an update and a bounty. – twodayslate Sep 27 '13 at 15:12
  • Answer the question and I'll give you the bounty @CodaFi. What you commented did help me out. – twodayslate Oct 01 '13 at 20:01
  • Alright, there. Thanks for the offer. – CodaFi Oct 02 '13 at 00:09

2 Answers2

4

Your problem is twofold. First, UITableView expects to be handed index paths containing both a row and a section, where you've provided it with only a row. Second, you cannot expect unchecked array access to succeed 100% of the time, so bounds check whatever access calls you might be using. It also wouldn't hurt to use some retains in the iVar assignments you've got in your code unless you don't need to hold a reference to it (but it looks like you do).

CodaFi
  • 43,043
  • 8
  • 107
  • 153
0

I figured out an alternative solution to ALDataSource. I sorted ALApplicationList.applications. The problem was that the instance of the sorted NSArray would keep disappearing. So I did [values retain] and everything worked! Reinitializing the sorted values was too slow and would crash the device.

Here is the working code that successfully lists all the apps: http://pastebin.ca/2459778

twodayslate
  • 2,803
  • 3
  • 27
  • 43