This is all my objects and i want to save all objects into single array.
**dataArray:**
<__NSArrayI 0x15e1a460>(
<__NSArrayM 0x15e244a0>(
<CKAsset: 0x15e69770; UUID=ED94A2F1-66C9-4D7C-B0E8-6A51EDBDDECE, arrayIndex=0, size=265849, path="/private~/Library/Caches/CloudKit/Assets/ED94A2F1-66C9-4D7C-B0E8-6A51EDBDDECE.01f8820d30f6147d76af04d3e84ccedc267da5f22d", signature=<01f8820d 30f6147d 76af04d3 e84ccedc 267da5f2 2d>, uploadRank=0>
)
,
<__NSArrayM 0x1706aac0>(
<CKAsset: 0x15ef1d90; UUID=46CA6A72-E1B4-4E03-AF8C-AEA557F62219, arrayIndex=0, size=49637, path="/private~/Library/Caches/CloudKit/Assets/46CA6A72-E1B4-4E03-AF8C-AEA557F62219.010c8944dcfd55b051c51c846092a61d4909708c97", signature=<010c8944 dcfd55b0 51c51c84 6092a61d 4909708c 97>, uploadRank=0>
)
,
<__NSArrayM 0x15e3f120>(
<CKAsset: 0x15e1ffc0; UUID=63018B1D-E340-4963-8BDC-8A2B5E108040, arrayIndex=0, size=102627, path="/private~/Library/Caches/CloudKit/Assets/63018B1D-E340-4963-8BDC-8A2B5E108040.0188b8d9b7cb6f914c2cd7fdb00b08aef3d1296ff0", signature=<0188b8d9 b7cb6f91 4c2cd7fd b00b08ae f3d1296f f0>, uploadRank=0>,
<CKAsset: 0x17057f00; UUID=96A26885-B0E2-4CCC-A571-07D94F22BB56, arrayIndex=1, size=88073, path="/private~/Library/Caches/CloudKit/Assets/96A26885-B0E2-4CCC-A571-07D94F22BB56.015bc1a8cc592f93343ad3baa7b5e92c1bd2c46099", signature=<015bc1a8 cc592f93 343ad3ba a7b5e92c 1bd2c460 99>, uploadRank=0>,
<CKAsset: 0x1706c5f0; UUID=E712BA16-4937-426C-88B4-5535B75F2507, arrayIndex=2, size=86948, path="/private~/Library/Caches/CloudKit/Assets/E712BA16-4937-426C-88B4-5535B75F2507.01a0f2f4bd2e4f92b6b0a530042db554f9904cb965", signature=<01a0f2f4 bd2e4f92 b6b0a530 042db554 f9904cb9 65>, uploadRank=0>
)
,
<__NSArrayM 0x15ecee30>(
<CKAsset: 0x15e3a980; UUID=66515C6E-0181-40C3-8A19-9BE4DBB3AFB5, arrayIndex=0, size=80674, path="/private~/Library/Caches/CloudKit/Assets/66515C6E-0181-40C3-8A19-9BE4DBB3AFB5.0187d802244e8b15b9a70e39755ce55433df6740cb", signature=<0187d802 244e8b15 b9a70e39 755ce554 33df6740 cb>, uploadRank=0>,
<CKAsset: 0x15ef3460; UUID=D80DC154-9278-4F46-9064-7888419C14D4, arrayIndex=1, size=29815, path="/private~/Library/Caches/CloudKit/Assets/D80DC154-9278-4F46-9064-7888419C14D4.012562c3defcf5833f065f305deb8bf83568147293", signature=<012562c3 defcf583 3f065f30 5deb8bf8 35681472 93>, uploadRank=0>
)
,
<__NSArrayM 0x15e3dec0>(
<CKAsset: 0x15e0c2c0; UUID=7357121B-18F6-4094-8844-19F79604FC88, arrayIndex=0, size=90252, path="/private~/Library/Caches/CloudKit/Assets/7357121B-18F6-4094-8844-19F79604FC88.01ee86884fc42ac4aa4ca519508e62e6b6306ad4fd", signature=<01ee8688 4fc42ac4 aa4ca519 508e62e6 b6306ad4 fd>, uploadRank=0>
)
)
I am using this loop for to get all objects and save into single Array:
for (int i = 0 ; i < dataArray.count; i++){
for (int j = 0 ; j<[[dataArray objectAtIndex:i] count]; j++) {
total addObject:[dataArray objectAtIndex:j]];
}
}
Using C-style iteration is not absolutely necessary, here's what you could do:
for(id object in dataArray) {
for(id subobject in object) {
[mutableArray addObject:subobject];
}
}
Related
I want to check the DB if IDs Column contains a specific ID or not?
I wrote something like this but this is WRONG as h:
dbHelper.ColID is a String
posts is a list ; the post model has an int ID ;
for(int i = 0 ; i<pageCount ; i++) {
for(int j=0 ; j<i; j++) {
if (dbHelper.ColID != posts[i].id){
dbHelper.insertPost(posts[0]) ;
}
}
Simply I used SQL query to get IDs from DB then put 2 loops together:
for (int i = 0; i < cachedPostsIDs.length; i++) {
for (int j = 0; j < postsIDs.length; j++) {
if (cachedPostsIDs.contains(postsIDs[j])) {
debugPrint("FOUND ${postsIDs[j]} post in the database");
} else {
foundPost = false;
debugPrint("COULDNT FIND ${postsIDs[j]} in cachedPostsIDs");
break;
}
}
I am loading a one to many relationship (and a bunch of other test data on initial load of my app into Core Data)
Side is an Entity with a one to many relationship of Frames:
let sideA = addNewSideToNSManagedObjectContext(orderInFlashcard: 0.0, frames: [frontFrame,backFrame], cardType: newCardType)
let sideB = addNewSideToNSManagedObjectContext(orderInFlashcard: 1.0, frames: [backFrame,frontFrame], cardType: newCardType)
//context is saved after code above
After the initial data is load, I present a tableViewController where I click through a row to present the loaded data (basically I show a flashcard's side1.frames and then flashcard's side2.frames)
When I do this after the initial data load everything works and displays properly, side1.frames has 2 items and side2.frames has 2 items and they all display properly.
THE PROBLEM: When I close the simulator and rerun it (after the first run, data is already there and not loaded again), When i click through to display a flashcard, side1.frames has 2 items BUT side2.frames is EMTPY and I get a blank display. I'm really stumped at what the problem is because all the other data is persisted.
THE DATA with the problem is being accessed based on the current flashcard i'm displaying like so:
flashcard.cardType.sides
each side.frame (for subviews)
When I present the sides/frames, here is the code that retrieves the data for display:
func setupFramesForSides(){
//var framesForSides:[[Frame]] = [[Frame]]() //property //goal to get array order by side.orderInFlashcard of arrays of frames for each side ordered by order in each side
var sides:[Side] = (flashcard!.cardType!.sides!.allObjects as! [Side])
sides.sort(by:{$0.orderInFlashcard<$1.orderInFlashcard}) //sides sorted by orderInFlashcard
currentSideIndex = 0
print("sides count:\(sides.count)")
for s in 0..<sides.count{
print("side:\(sides[s].orderInFlashcard)")
}
for sideIndex in 0..<sides.count{
let side:Side = sides[sideIndex]
print("currentSideIndex: \(sideIndex)")
print("currentSide: \(side)")
//create sorted array of frames for the side
let frames:[Frame] = side.frames!.allObjects as! [Frame]
print("framesAvailable:\(frames)")
print("framesAvailable.count:\(frames.count)")
//frames.sort(by:{$0<$1})
var frameOrdersInSide:[Int:Frame] = [Int:Frame]()
print("PREPARING NEW SIDE'S FRAMES")
for sideFrame in frames{
for orderInSide in sideFrame.orderInSides!.allObjects as! [FrameOrderInSide]{
if orderInSide.side == side {
print("FOUND MATCHING SIDE IN FRAME.ORDERINSIDES")
print("orderInSide:\(orderInSide.index)")
print("sideFrame:\(sideFrame)")
frameOrdersInSide[Int(orderInSide.index)] = sideFrame //index for frame in this side should never match another frame's index
}
}
}
print("frameOrdersInSide:\(frameOrdersInSide)")
print("frameOrdersInSide.count:\(frameOrdersInSide.count)")
var sortedFramesInSide:[Frame] = [Frame]()
for frameIndexInSide in 0..<(frameOrdersInSide.keys.sorted(by:{$0<$1})).count{
sortedFramesInSide.append(frameOrdersInSide[frameIndexInSide]!) //array of Frames in order of the index in the side
}
framesForSides.append(sortedFramesInSide)
}
Here are the console results from display from the initial load of the data without closing the simulator:
sides count:2
side:0.0
side:1.0
currentSideIndex: 0
currentSide: <FlashTags.Side: 0x6000000898d0> (entity: Side; id: 0xd000000000040010 <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Side/p1> ; data: {
frames = (
"0xd00000000004000a <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p1>",
"0xd00000000008000a <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p2>"
);
orderInFlashcard = 0;
})
framesAvailable:[<FlashTags.Frame: 0x600000089740> (entity: Frame; id: 0xd00000000004000a <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p1> ; data: {
html = "{{kanjiImage}}";
name = back;
orderInSides = (
"0xd00000000008000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p2>",
"0xd00000000004000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p1>"
);
}), <FlashTags.Frame: 0x600000089510> (entity: Frame; id: 0xd00000000008000a <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p2> ; data: {
html = "{{englishKeyword}}";
name = front;
orderInSides = (
"0xd00000000010000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p4>",
"0xd0000000000c000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p3>"
);
})]
framesAvailable.count:2
PREPARING NEW SIDE'S FRAMES
FOUND MATCHING SIDE IN FRAME.ORDERINSIDES
orderInSide:1.0
sideFrame:<FlashTags.Frame: 0x600000089740> (entity: Frame; id: 0xd00000000004000a <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p1> ; data: {
html = "{{kanjiImage}}";
name = back;
orderInSides = (
"0xd00000000008000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p2>",
"0xd00000000004000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p1>"
);
})
FOUND MATCHING SIDE IN FRAME.ORDERINSIDES
orderInSide:0.0
sideFrame:<FlashTags.Frame: 0x600000089510> (entity: Frame; id: 0xd00000000008000a <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p2> ; data: {
html = "{{englishKeyword}}";
name = front;
orderInSides = (
"0xd00000000010000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p4>",
"0xd0000000000c000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p3>"
);
})
frameOrdersInSide:[0: <FlashTags.Frame: 0x600000089510> (entity: Frame; id: 0xd00000000008000a <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p2> ; data: {
html = "{{englishKeyword}}";
name = front;
orderInSides = (
"0xd00000000010000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p4>",
"0xd0000000000c000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p3>"
);
}), 1: <FlashTags.Frame: 0x600000089740> (entity: Frame; id: 0xd00000000004000a <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p1> ; data: {
html = "{{kanjiImage}}";
name = back;
orderInSides = (
"0xd00000000008000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p2>",
"0xd00000000004000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p1>"
);
})]
frameOrdersInSide.count:2
currentSideIndex: 1
currentSide: <FlashTags.Side: 0x61800008a7d0> (entity: Side; id: 0xd000000000080010 <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Side/p2> ; data: {
frames = (
"0xd00000000004000a <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p1>",
"0xd00000000008000a <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p2>"
);
orderInFlashcard = 1;
})
framesAvailable:[<FlashTags.Frame: 0x600000089740> (entity: Frame; id: 0xd00000000004000a <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p1> ; data: {
html = "{{kanjiImage}}";
name = back;
orderInSides = (
"0xd00000000008000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p2>",
"0xd00000000004000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p1>"
);
}), <FlashTags.Frame: 0x600000089510> (entity: Frame; id: 0xd00000000008000a <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p2> ; data: {
html = "{{englishKeyword}}";
name = front;
orderInSides = (
"0xd00000000010000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p4>",
"0xd0000000000c000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p3>"
);
})]
framesAvailable.count:2
PREPARING NEW SIDE'S FRAMES
FOUND MATCHING SIDE IN FRAME.ORDERINSIDES
orderInSide:0.0
sideFrame:<FlashTags.Frame: 0x600000089740> (entity: Frame; id: 0xd00000000004000a <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p1> ; data: {
html = "{{kanjiImage}}";
name = back;
orderInSides = (
"0xd00000000008000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p2>",
"0xd00000000004000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p1>"
);
})
FOUND MATCHING SIDE IN FRAME.ORDERINSIDES
orderInSide:1.0
sideFrame:<FlashTags.Frame: 0x600000089510> (entity: Frame; id: 0xd00000000008000a <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p2> ; data: {
html = "{{englishKeyword}}";
name = front;
orderInSides = (
"0xd00000000010000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p4>",
"0xd0000000000c000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p3>"
);
})
frameOrdersInSide:[0: <FlashTags.Frame: 0x600000089740> (entity: Frame; id: 0xd00000000004000a <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p1> ; data: {
html = "{{kanjiImage}}";
name = back;
orderInSides = (
"0xd00000000008000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p2>",
"0xd00000000004000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p1>"
);
}), 1: <FlashTags.Frame: 0x600000089510> (entity: Frame; id: 0xd00000000008000a <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p2> ; data: {
html = "{{englishKeyword}}";
name = front;
orderInSides = (
"0xd00000000010000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p4>",
"0xd0000000000c000c <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p3>"
);
})]
frameOrdersInSide.count:2
After Closing the simulator, this is the issue as seen in the console:
sides count:2
side:0.0
side:1.0
currentSideIndex: 0
currentSide: <FlashTags.Side: 0x600000289420> (entity: Side; id: 0xd00000000004000e <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Side/p1> ; data: {
frames = "<relationship fault: 0x600000028940 'frames'>";
orderInFlashcard = 0;
})
framesAvailable:[<FlashTags.Frame: 0x600000286810> (entity: Frame; id: 0xd000000000040010 <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p1> ; data: <fault>), <FlashTags.Frame: 0x600000286bd0> (entity: Frame; id: 0xd000000000080010 <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p2> ; data: <fault>)]
framesAvailable.count:2
PREPARING NEW SIDE'S FRAMES
FOUND MATCHING SIDE IN FRAME.ORDERINSIDES
orderInSide:1.0
sideFrame:<FlashTags.Frame: 0x600000286810> (entity: Frame; id: 0xd000000000040010 <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p1> ; data: {
html = "{{kanjiImage}}";
name = back;
orderInSides = (
"0xd000000000080012 <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p2>",
"0xd000000000040012 <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p1>"
);
})
FOUND MATCHING SIDE IN FRAME.ORDERINSIDES
orderInSide:0.0
sideFrame:<FlashTags.Frame: 0x600000286bd0> (entity: Frame; id: 0xd000000000080010 <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p2> ; data: {
html = "{{englishKeyword}}";
name = front;
orderInSides = (
"0xd0000000000c0012 <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p3>",
"0xd000000000100012 <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p4>"
);
})
frameOrdersInSide:[0: <FlashTags.Frame: 0x600000286bd0> (entity: Frame; id: 0xd000000000080010 <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p2> ; data: {
html = "{{englishKeyword}}";
name = front;
orderInSides = (
"0xd0000000000c0012 <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p3>",
"0xd000000000100012 <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p4>"
);
}), 1: <FlashTags.Frame: 0x600000286810> (entity: Frame; id: 0xd000000000040010 <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Frame/p1> ; data: {
html = "{{kanjiImage}}";
name = back;
orderInSides = (
"0xd000000000080012 <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p2>",
"0xd000000000040012 <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/FrameOrderInSide/p1>"
);
})]
frameOrdersInSide.count:2
currentSideIndex: 1
currentSide: <FlashTags.Side: 0x6000002894c0> (entity: Side; id: 0xd00000000008000e <x-coredata://AABA51C1-C3ED-4701-A7DD-BE1CB7B66995/Side/p2> ; data: {
frames = "<relationship fault: 0x600000029b00 'frames'>";
orderInFlashcard = 1;
})
framesAvailable:[]
framesAvailable.count:0
PREPARING NEW SIDE'S FRAMES
frameOrdersInSide:[:]
frameOrdersInSide.count:0
Here's the updated flashcard loading code after changing my core data design:
var sides:[Side] = (flashcard!.cardType!.sides!.allObjects as! [Side])
sides.sort(by:{$0.orderInFlashcard<$1.orderInFlashcard}) //sides sorted by orderInFlashcard
currentSideIndex = 0
for sideIndex in 0..<sides.count{
let side:Side = sides[sideIndex]
let framesOrderInSide:[FrameOrderInSide] = (side.frameOrders!.allObjects as! [FrameOrderInSide]).sorted(by:{$0.index<$1.index})
framesForSides.append(framesOrderInSide.map({$0.frame}))
}
I have array of array and want to eliminate duplicity. How can I do this
<__NSArrayM 0x9175640>(
<__NSArrayI 0x919ec80>(
http://scontent-b.cdninstagram.com/hphotos-xfp1/outbound-distilleryimage2/t0.0-17/OBPTH/dccd6b4cb15211e3aeb912af24c9b212_5.jpg,
47738394,
evdokia_bach,
Evdokia Bach,
https://instagramimages-a.akamaihd.net/profiles/profile_47738394_75sq_1388023560.jpg
)
,
<__NSArrayI 0x919eca0>(
http://scontent-b.cdninstagram.com/hphotos-xpf1/outbound-distilleryimage10/t0.0-17/OBPTH/e27402bab15011e39584123223ad70da_5.jpg,
47799994,
allen,
allen warden,
https://instagramimages-a.akamaihd.net/profiles/profile_47738394_75sq_1388023560.jpg
)
,
<__NSArrayI 0x919ecc0>(
http://scontent-a.cdninstagram.com/hphotos-xaf1/outbound-distilleryimage6/t0.0-17/OBPTH/5794c4e0b15011e397e2122466b7dba2_5.jpg,
47738394,
evdokia_bach,
Evdokia Bach,
https://instagramimages-a.akamaihd.net/profiles/profile_47738394_75sq_1388023560.jpg
)
,
<__NSArrayI 0x919ece0>(
http://scontent-b.cdninstagram.com/hphotos-xpf1/outbound-distilleryimage11/t0.0-17/OBPTH/0f0916eab15011e3942d12c36745260f_5.jpg,
47738394,
evdokia_bach,
Evdokia Bach,
https://instagramimages-a.akamaihd.net/profiles/profile_47738394_75sq_1388023560.jpg
)
)
)
I want only unique array how can i do this ?
This is my implementation for an insertion sort method using linkedList. I have tried it and it works just fine the only problem that there is an index out of bounds exception caused by the J+1 line. Can anyone tell me how to get around that or how to fix it. Thnx
public static <T extends Comparable <? super T>> void insertionSort2(List<T> portion){
int i = 0;
int j = 0;
T value;
//List <T> sorted = new LinkedList<T>();
// goes through the list
for (i = 1; i < portion.size(); i++) {
// takes each value of the list
value = (T) portion.remove(i);
// the index j takes the value of I and checks the rest of the array
// from the point i
j = i - 1;
while (j >= 0 && (portion.get(j).compareTo(value) >= 0)) {
portion.add(j+1 , portion.remove(j));//it was j+1
j--;
}
// put the value in the correct location.
portion.add(j + 1, value);
}
}
check this code out
just put it as a function in a class and try to call it
void InsertionSort()
{
int temp, out, in;
for(out=1 ; out<size ; out++)
{
temp = list[out];
in = out;
while (in > 0 && list[in-1] > temp)
{
list[in] = list[in-1];
--in;
}
list[in]= temp;
System.out.print("The list in this step became: ");
for (int t=0 ; t<size ; t++)
System.out.print(list[t]+" ");
System.out.println("");
}
}
Can someone please help me. Im very new at this and trying to seque to my detail screen, which works fine as long as i don't use sections. The files i try to grab in the detail are html files.
(numbered 1 - 53). When is seque to detail without sections i simply use
htmlFile = [artikelen objectAtIndex:[path row]] to seque;
When i use sections [path row] will be something like [0.1] instead of continues numbering.
I sure hope someone can help me solve and understand this problem.
Thanks.
Jaco
[super viewDidLoad];
artikelen = [[NSMutableArray alloc]initWithObjects:#"artikel1",#"artikel2",#"artikel3",#"artikel4",#"artikel5",#"artikel6",#"artikel7",#"artikel8",#"artikel9",#"artikel10",#"artikel11",#"artikel12",#"artikel13",#"artikel14",#"artikel15",#"artikel16",#"artikel17",#"artikel18",#"artikel19",#"artikel20",#"artikel21",#"artikel22",#"artikel23",#"artikel24",#"artikel25",#"artikel26",#"artikel27",#"artikel28",#"artikel29",#"artikel30",#"artikel31",#"artikel32",#"artikel33",#"artikel34",#"artikel35",#"artikel36",#"artikel37",#"artikel38",#"artikel39",#"artikel40",#"artikel41",#"artikel42",#"artikel43",#"artikel44",#"artikel45",#"artikel46",#"artikel47",#"artikel48",#"artikel49",#"artikel50",#"artikel51",#"artikel52",#"artikel53",#"artikel54", nil];
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 14;
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
NSArray *sectionTitles = [[NSArray alloc]
initWithObjects:#"Hoofdstuk I.", #"Hoofdstuk
II.",#"Hoofdstuk III.",#"Hoofdstuk IV.",#"Hoofdstuk IVA.",#"Hoofdstuk IVB.",#"Hoofdstuk
V.",#"Hoofdstuk VA.",#"Hoofdstuk VI.",#"Hoofdstuk VII.",#"Hoofdstuk VII B.",
#"Hoofdstuk VIIC.",#"Hoofdstuk VIII.",nil];
return sectionTitles;
}
- (NSString *)tableView:(UITableView *)tableView
titleForHeaderInSection:(NSInteger)section
{
if ( section == 0 ) return #"Hoofdstuk I. Algemeen";
if ( section == 1 ) return #"Hoofdstuk II. De instelling";
if ( section == 2 ) return #"Hoofdstuk III. Samenstelling ";
if ( section == 3 ) return #"Hoofdstuk IV. Het overleg ";
if ( section == 4 ) return #"Hoofdstuk IVA. bevoegdheden ";
if ( section == 5 ) return #"Hoofdstuk IVB. Hgegevens aan de ondernemingsraad";
if ( section == 6 ) return #"Hoofdstuk IVC. Verdere bevoegdheden van de";
if ( section == 7 ) return #"Hoofdstuk V. De centrale ";
if ( section == 8 ) return #"Hoofdstuk VA.";
if ( section == 9 ) return #"Hoofdstuk VI. De algemene";
if ( section == 10 ) return #"Hoofdstuk VII.";
if ( section == 11 ) return #"Hoofdstuk VII. A.de overheid";
if ( section == 12 ) return #"Hoofdstuk VII. B ";
if ( section == 13 ) return #"Hoofdstuk VIII";
return #"Other";
}
To display the right number of rows i used:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ( section == 0 ) return 1;
if ( section == 1 ) return 4;
... etcetra
return 0;
}
To display the right cell i've used:
if ( indexPath.section == 12 ) mijnRij += 45; //7a
if ( indexPath.section == 13 ) mijnRij += 56; //8
cell.textLabel.text = [artikelen objectAtIndex:mijnRij];
return cell;
If you use a better data structure it will make the coding much easier.
I suggest that your main structure should be an array of dictionaries. Each dictionary should match a section and contain two keys. The first key should give you the section header and the second key should give you an array that matches the rows in that section.
That way you don't need so many conditions. The section number tells you which dictionary to use and the row tells you where to look in the dictionary's sub-array.